|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py |
| 2 | +; RUN: opt < %s "-passes=print<scev-division>" -disable-output 2>&1 | FileCheck %s |
| 3 | + |
| 4 | +define noundef i8 @add(i8 %x, i8 %y) { |
| 5 | +; CHECK-LABEL: 'add' |
| 6 | +; CHECK-NEXT: Instruction: %div = sdiv i8 %add, %y |
| 7 | +; CHECK-NEXT: Numerator: (%x + %y) |
| 8 | +; CHECK-NEXT: Denominator: %y |
| 9 | +; CHECK-NEXT: Quotient: 1 |
| 10 | +; CHECK-NEXT: Remainder: %x |
| 11 | +; |
| 12 | + %add = add i8 %x, %y |
| 13 | + %div = sdiv i8 %add, %y |
| 14 | + ret i8 %div |
| 15 | +} |
| 16 | + |
| 17 | +define noundef i8 @mul_add_mul(i8 %a, i8 %b, i8 %c) { |
| 18 | +; CHECK-LABEL: 'mul_add_mul' |
| 19 | +; CHECK-NEXT: Instruction: %div = sdiv i8 %add, %a |
| 20 | +; CHECK-NEXT: Numerator: ((2 * %c)<nuw><nsw> + (%a * %b)<nuw><nsw>)<nuw><nsw> |
| 21 | +; CHECK-NEXT: Denominator: %a |
| 22 | +; CHECK-NEXT: Quotient: %b |
| 23 | +; CHECK-NEXT: Remainder: (2 * %c)<nuw><nsw> |
| 24 | +; |
| 25 | + %mul0 = mul nsw nuw i8 %a, %b |
| 26 | + %mul1 = mul nsw nuw i8 %c, 2 |
| 27 | + %add = add nsw nuw i8 %mul0, %mul1 |
| 28 | + %div = sdiv i8 %add, %a |
| 29 | + ret i8 %div |
| 30 | +} |
| 31 | + |
| 32 | +define noundef i8 @mul(i8 %x, i8 %y) { |
| 33 | +; CHECK-LABEL: 'mul' |
| 34 | +; CHECK-NEXT: Instruction: %div = sdiv i8 %mul, %y |
| 35 | +; CHECK-NEXT: Numerator: (%x * %y) |
| 36 | +; CHECK-NEXT: Denominator: %y |
| 37 | +; CHECK-NEXT: Quotient: %x |
| 38 | +; CHECK-NEXT: Remainder: 0 |
| 39 | +; |
| 40 | + %mul = mul i8 %x, %y |
| 41 | + %div = sdiv i8 %mul, %y |
| 42 | + ret i8 %div |
| 43 | +} |
| 44 | + |
| 45 | +define noundef i8 @add_mul_add(i8 %a, i8 %b, i8 %c) { |
| 46 | +; CHECK-LABEL: 'add_mul_add' |
| 47 | +; CHECK-NEXT: Instruction: %div = sdiv i8 %mul, %a |
| 48 | +; CHECK-NEXT: Numerator: ((%a + %b)<nuw><nsw> * (%a + %c)<nuw><nsw>)<nuw><nsw> |
| 49 | +; CHECK-NEXT: Denominator: %a |
| 50 | +; CHECK-NEXT: Quotient: 0 |
| 51 | +; CHECK-NEXT: Remainder: ((%a + %b)<nuw><nsw> * (%a + %c)<nuw><nsw>)<nuw><nsw> |
| 52 | +; |
| 53 | + %add0 = add nsw nuw i8 %a, %b |
| 54 | + %add1 = add nsw nuw i8 %a, %c |
| 55 | + %mul = mul nsw nuw i8 %add0, %add1 |
| 56 | + %div = sdiv i8 %mul, %a |
| 57 | + ret i8 %div |
| 58 | +} |
| 59 | + |
| 60 | +; for (i = 0; i < n; i++) |
| 61 | +; div = i / den; |
| 62 | +; |
| 63 | +define void @addrec_iv(i8 %n, i8 %den) { |
| 64 | +; CHECK-LABEL: 'addrec_iv' |
| 65 | +; CHECK-NEXT: Instruction: %div = sdiv i8 %i, %den |
| 66 | +; CHECK-NEXT: Numerator: {0,+,1}<nuw><nsw><%loop> |
| 67 | +; CHECK-NEXT: Denominator: %den |
| 68 | +; CHECK-NEXT: Quotient: 0 |
| 69 | +; CHECK-NEXT: Remainder: {0,+,1}<nuw><nsw><%loop> |
| 70 | +; |
| 71 | +entry: |
| 72 | + %guard = icmp sgt i8 %n, 0 |
| 73 | + br i1 %guard, label %loop, label %exit |
| 74 | + |
| 75 | +loop: |
| 76 | + %i = phi i8 [ 0, %entry ], [ %i.inc, %loop ] |
| 77 | + %div = sdiv i8 %i, %den |
| 78 | + %i.inc = add nsw i8 %i, 1 |
| 79 | + %exitcond = icmp eq i8 %i.inc, %n |
| 80 | + br i1 %exitcond, label %exit, label %loop |
| 81 | + |
| 82 | +exit: |
| 83 | + ret void |
| 84 | +} |
| 85 | + |
| 86 | +; for (i = 0; i < n; i++) |
| 87 | +; div = (step * i) / step; |
| 88 | +; |
| 89 | +define void @addrec_step0(i8 %n, i8 %step) { |
| 90 | +; CHECK-LABEL: 'addrec_step0' |
| 91 | +; CHECK-NEXT: Instruction: %div = sdiv i8 %num, %step |
| 92 | +; CHECK-NEXT: Numerator: {0,+,%step}<nuw><nsw><%loop> |
| 93 | +; CHECK-NEXT: Denominator: %step |
| 94 | +; CHECK-NEXT: Quotient: {0,+,1}<nuw><nsw><%loop> |
| 95 | +; CHECK-NEXT: Remainder: 0 |
| 96 | +; |
| 97 | +entry: |
| 98 | + %guard = icmp sgt i8 %n, 0 |
| 99 | + br i1 %guard, label %loop, label %exit |
| 100 | + |
| 101 | +loop: |
| 102 | + %i = phi i8 [ 0, %entry ], [ %i.inc, %loop ] |
| 103 | + %num = phi i8 [ 0, %entry ], [ %num.next, %loop ] |
| 104 | + %div = sdiv i8 %num, %step |
| 105 | + %i.inc = add nsw i8 %i, 1 |
| 106 | + %num.next = add nsw nuw i8 %num, %step |
| 107 | + %exitcond = icmp eq i8 %i.inc, %n |
| 108 | + br i1 %exitcond, label %exit, label %loop |
| 109 | + |
| 110 | +exit: |
| 111 | + ret void |
| 112 | +} |
| 113 | + |
| 114 | +; for (unsigned char i = 0; i < n; i++) |
| 115 | +; if (cond) |
| 116 | +; div = (step * i) / step; |
| 117 | +; |
| 118 | +; FIXME: The quotient can cause signed wrap, e.g., when %step is 0 and %n is |
| 119 | +; larger than 127. |
| 120 | +define void @addrec_step1(i8 %n, i8 %step) { |
| 121 | +; CHECK-LABEL: 'addrec_step1' |
| 122 | +; CHECK-NEXT: Instruction: %div = sdiv i8 %num, %step |
| 123 | +; CHECK-NEXT: Numerator: {0,+,%step}<nuw><nsw><%loop.header> |
| 124 | +; CHECK-NEXT: Denominator: %step |
| 125 | +; CHECK-NEXT: Quotient: {0,+,1}<nuw><nsw><%loop.header> |
| 126 | +; CHECK-NEXT: Remainder: 0 |
| 127 | +; |
| 128 | +entry: |
| 129 | + %guard = icmp ne i8 %n, 0 |
| 130 | + br i1 %guard, label %loop.header, label %exit |
| 131 | + |
| 132 | +loop.header: |
| 133 | + %i = phi i8 [ 0, %entry ], [ %i.inc, %loop.latch ] |
| 134 | + %num = phi i8 [ 0, %entry ], [ %num.next, %loop.latch ] |
| 135 | + %cond = freeze i1 poison |
| 136 | + br i1 %cond, label %division, label %loop.latch |
| 137 | + |
| 138 | +division: |
| 139 | + %div = sdiv i8 %num, %step |
| 140 | + br label %loop.latch |
| 141 | + |
| 142 | +loop.latch: |
| 143 | + %i.inc = add nuw i8 %i, 1 |
| 144 | + %num.next = add nsw nuw i8 %num, %step |
| 145 | + %exitcond = icmp eq i8 %i.inc, %n |
| 146 | + br i1 %exitcond, label %exit, label %loop.header |
| 147 | + |
| 148 | +exit: |
| 149 | + ret void |
| 150 | +} |
| 151 | + |
| 152 | +; for (i = 0; i < n; i++) |
| 153 | +; div = (a + b) * i / a; |
| 154 | +; |
| 155 | +; FIXME: Both the quotient and the remainder can cause signed/unsigned wrap, |
| 156 | +; e.g., when %a + %b = 0 && %a != 0. |
| 157 | +define void @addrec_a_b(i8 %n, i8 %a, i8 %b) { |
| 158 | +; CHECK-LABEL: 'addrec_a_b' |
| 159 | +; CHECK-NEXT: Instruction: %div = sdiv i8 %num, %step |
| 160 | +; CHECK-NEXT: Numerator: {0,+,(%a + %b)}<nuw><nsw><%loop> |
| 161 | +; CHECK-NEXT: Denominator: (%a + %b) |
| 162 | +; CHECK-NEXT: Quotient: {0,+,1}<nuw><nsw><%loop> |
| 163 | +; CHECK-NEXT: Remainder: 0 |
| 164 | +; |
| 165 | +entry: |
| 166 | + %guard = icmp sgt i8 %n, 0 |
| 167 | + %step = add nsw nuw i8 %a, %b |
| 168 | + br i1 %guard, label %loop, label %exit |
| 169 | + |
| 170 | +loop: |
| 171 | + %i = phi i8 [ 0, %entry ], [ %i.inc, %loop ] |
| 172 | + %num = phi i8 [ 0, %entry ], [ %num.next, %loop ] |
| 173 | + %div = sdiv i8 %num, %step |
| 174 | + %i.inc = add nsw i8 %i, 1 |
| 175 | + %num.next = add nsw nuw i8 %num, %step |
| 176 | + %exitcond = icmp eq i8 %i.inc, %n |
| 177 | + br i1 %exitcond, label %exit, label %loop |
| 178 | + |
| 179 | +exit: |
| 180 | + ret void |
| 181 | +} |
0 commit comments