Home | History | Annotate | Download | only in LoopStrengthReduce
      1 ; RUN: opt < %s -analyze -iv-users | FileCheck %s
      2 
      3 ; Provide legal integer types.
      4 target datalayout = "n8:16:32:64"
      5 
      6 ; The value of %r is dependent on a polynomial iteration expression.
      7 ;
      8 ; CHECK-LABEL: IV Users for loop %foo.loop
      9 ; CHECK: {1,+,3,+,2}<%foo.loop>
     10 define i64 @foo(i64 %n) {
     11 entry:
     12   br label %foo.loop
     13 
     14 foo.loop:
     15   %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %foo.loop ]
     16   %indvar.next = add i64 %indvar, 1
     17   %c = icmp eq i64 %indvar.next, %n
     18   br i1 %c, label %exit, label %foo.loop
     19 
     20 exit:
     21   %r = mul i64 %indvar.next, %indvar.next
     22   ret i64 %r
     23 }
     24 
     25 ; PR15470: LSR miscompile. The test2 function should return '1'.
     26 ;
     27 ; SCEV does not know how to denormalize chained recurrences, so make
     28 ; sure they aren't marked as post-inc users.
     29 ;
     30 ; CHECK-LABEL: IV Users for loop %test2.loop
     31 ; CHECK: %sext.us = {0,+,(16777216 + (-16777216 * %sub.us))<nuw><nsw>,+,33554432}<%test2.loop> in %f = ashr i32 %sext.us, 24
     32 define i32 @test2() {
     33 entry:
     34   br label %test2.loop
     35 
     36 test2.loop:
     37   %inc1115.us = phi i32 [ 0, %entry ], [ %inc11.us, %test2.loop ]
     38   %inc11.us = add nsw i32 %inc1115.us, 1
     39   %cmp.us = icmp slt i32 %inc11.us, 2
     40   br i1 %cmp.us, label %test2.loop, label %for.end
     41 
     42 for.end:
     43   %tobool.us = icmp eq i32 %inc1115.us, 0
     44   %sub.us = select i1 %tobool.us, i32 0, i32 0
     45   %mul.us = shl i32 %inc1115.us, 24
     46   %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us
     47   %sext.us = mul i32 %mul.us, %sub.cond.us
     48   %f = ashr i32 %sext.us, 24
     49   br label %exit
     50 
     51 exit:
     52   ret i32 %f
     53 }
     54