brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.0 KiB · e3cf15e Raw
182 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py2; RUN: opt < %s "-passes=print<scev-division>" -disable-output 2>&1 | FileCheck %s3 4define noundef i8 @add(i8 %x, i8 %y) {5; CHECK-LABEL: 'add'6; CHECK-NEXT:  Instruction: %div = sdiv i8 %add, %y7; CHECK-NEXT:    Numerator: (%x + %y)8; CHECK-NEXT:    Denominator: %y9; CHECK-NEXT:    Quotient: 110; CHECK-NEXT:    Remainder: %x11;12  %add = add i8 %x, %y13  %div = sdiv i8 %add, %y14  ret i8 %div15}16 17define 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, %a20; CHECK-NEXT:    Numerator: ((2 * %c)<nuw><nsw> + (%a * %b)<nuw><nsw>)<nuw><nsw>21; CHECK-NEXT:    Denominator: %a22; CHECK-NEXT:    Quotient: %b23; CHECK-NEXT:    Remainder: (2 * %c)<nuw><nsw>24;25  %mul0 = mul nsw nuw i8 %a, %b26  %mul1 = mul nsw nuw i8 %c, 227  %add = add nsw nuw i8 %mul0, %mul128  %div = sdiv i8 %add, %a29  ret i8 %div30}31 32define noundef i8 @mul(i8 %x, i8 %y) {33; CHECK-LABEL: 'mul'34; CHECK-NEXT:  Instruction: %div = sdiv i8 %mul, %y35; CHECK-NEXT:    Numerator: (%x * %y)36; CHECK-NEXT:    Denominator: %y37; CHECK-NEXT:    Quotient: %x38; CHECK-NEXT:    Remainder: 039;40  %mul = mul i8 %x, %y41  %div = sdiv i8 %mul, %y42  ret i8 %div43}44 45define 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, %a48; CHECK-NEXT:    Numerator: ((%a + %b)<nuw><nsw> * (%a + %c)<nuw><nsw>)<nuw><nsw>49; CHECK-NEXT:    Denominator: %a50; CHECK-NEXT:    Quotient: 051; CHECK-NEXT:    Remainder: ((%a + %b)<nuw><nsw> * (%a + %c)<nuw><nsw>)<nuw><nsw>52;53  %add0 = add nsw nuw i8 %a, %b54  %add1 = add nsw nuw i8 %a, %c55  %mul = mul nsw nuw i8 %add0, %add156  %div = sdiv i8 %mul, %a57  ret i8 %div58}59 60; for (i = 0; i < n; i++)61;   div = i / den;62;63define void @addrec_iv(i8 %n, i8 %den) {64; CHECK-LABEL: 'addrec_iv'65; CHECK-NEXT:  Instruction: %div = sdiv i8 %i, %den66; CHECK-NEXT:    Numerator: {0,+,1}<nuw><nsw><%loop>67; CHECK-NEXT:    Denominator: %den68; CHECK-NEXT:    Quotient: 069; CHECK-NEXT:    Remainder: {0,+,1}<nuw><nsw><%loop>70;71entry:72  %guard = icmp sgt i8 %n, 073  br i1 %guard, label %loop, label %exit74 75loop:76  %i = phi i8 [ 0, %entry ], [ %i.inc, %loop ]77  %div = sdiv i8 %i, %den78  %i.inc = add nsw i8 %i, 179  %exitcond = icmp eq i8 %i.inc, %n80  br i1 %exitcond, label %exit, label %loop81 82exit:83  ret void84}85 86; for (i = 0; i < n; i++)87;   div = (step * i) / step;88;89define void @addrec_step0(i8 %n, i8 %step) {90; CHECK-LABEL: 'addrec_step0'91; CHECK-NEXT:  Instruction: %div = sdiv i8 %num, %step92; CHECK-NEXT:    Numerator: {0,+,%step}<nuw><nsw><%loop>93; CHECK-NEXT:    Denominator: %step94; CHECK-NEXT:    Quotient: {0,+,1}<nuw><nsw><%loop>95; CHECK-NEXT:    Remainder: 096;97entry:98  %guard = icmp sgt i8 %n, 099  br i1 %guard, label %loop, label %exit100 101loop:102  %i = phi i8 [ 0, %entry ], [ %i.inc, %loop ]103  %num = phi i8 [ 0, %entry ], [ %num.next, %loop ]104  %div = sdiv i8 %num, %step105  %i.inc = add nsw i8 %i, 1106  %num.next = add nsw nuw i8 %num, %step107  %exitcond = icmp eq i8 %i.inc, %n108  br i1 %exitcond, label %exit, label %loop109 110exit:111  ret void112}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 is119; larger than 127.120define void @addrec_step1(i8 %n, i8 %step) {121; CHECK-LABEL: 'addrec_step1'122; CHECK-NEXT:  Instruction: %div = sdiv i8 %num, %step123; CHECK-NEXT:    Numerator: {0,+,%step}<nuw><nsw><%loop.header>124; CHECK-NEXT:    Denominator: %step125; CHECK-NEXT:    Quotient: {0,+,1}<nuw><nsw><%loop.header>126; CHECK-NEXT:    Remainder: 0127;128entry:129  %guard = icmp ne i8 %n, 0130  br i1 %guard, label %loop.header, label %exit131 132loop.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 poison136  br i1 %cond, label %division, label %loop.latch137 138division:139  %div = sdiv i8 %num, %step140  br label %loop.latch141 142loop.latch:143  %i.inc = add nuw i8 %i, 1144  %num.next = add nsw nuw i8 %num, %step145  %exitcond = icmp eq i8 %i.inc, %n146  br i1 %exitcond, label %exit, label %loop.header147 148exit:149  ret void150}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.157define void @addrec_a_b(i8 %n, i8 %a, i8 %b) {158; CHECK-LABEL: 'addrec_a_b'159; CHECK-NEXT:  Instruction: %div = sdiv i8 %num, %step160; 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: 0164;165entry:166  %guard = icmp sgt i8 %n, 0167  %step = add nsw nuw i8 %a, %b168  br i1 %guard, label %loop, label %exit169 170loop:171  %i = phi i8 [ 0, %entry ], [ %i.inc, %loop ]172  %num = phi i8 [ 0, %entry ], [ %num.next, %loop ]173  %div = sdiv i8 %num, %step174  %i.inc = add nsw i8 %i, 1175  %num.next = add nsw nuw i8 %num, %step176  %exitcond = icmp eq i8 %i.inc, %n177  br i1 %exitcond, label %exit, label %loop178 179exit:180  ret void181}182