Home | History | Annotate | Download | only in LoopStrengthReduce
      1 ; RUN: opt < %s -loop-reduce -S | FileCheck %s
      2 
      3 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
      4 
      5 ; for (int i = 0; i < n; ++i) {
      6 ;   use(i * 5 + 3);
      7 ;   // i * a + b is ephemeral and shouldn't be promoted by LSR
      8 ;   __builtin_assume(i * a + b >= 0);
      9 ; }
     10 define void @ephemeral(i32 %a, i32 %b, i32 %n) {
     11 ; CHECK-LABEL: @ephemeral(
     12 entry:
     13   br label %loop
     14 
     15 loop:
     16   %i = phi i32 [ 0, %entry ], [ %inc, %loop ]
     17   ; Only i and i * 5 + 3 should be indvars, not i * a + b.
     18 ; CHECK: phi i32
     19 ; CHECK: phi i32
     20 ; CHECK-NOT: phi i32
     21   %inc = add nsw i32 %i, 1
     22   %exitcond = icmp eq i32 %inc, %n
     23 
     24   %0 = mul nsw i32 %i, 5
     25   %1 = add nsw i32 %0, 3
     26   call void @use(i32 %1)
     27 
     28   %2 = mul nsw i32 %i, %a
     29   %3 = add nsw i32 %2, %b
     30   %4 = icmp sgt i32 %3, -1
     31   call void @llvm.assume(i1 %4)
     32 
     33   br i1 %exitcond, label %exit, label %loop
     34 
     35 exit:
     36   ret void
     37 }
     38 
     39 declare void @use(i32)
     40 
     41 declare void @llvm.assume(i1)
     42