Home | History | Annotate | Download | only in IndVarSimplify
      1 ; RUN: opt -indvars -S < %s | FileCheck %s
      2 
      3 define i32 @fn() {
      4 entry:
      5   ret i32 10
      6 }
      7 
      8 define i32 @test_nested2(i32 %tnr) {
      9 ; CHECK-LABEL: test_nested2
     10 ; CHECK-NOT: %indvars.iv
     11 ; CHECK: %i.0
     12 
     13 ; indvars should not replace the i.0 variable with a new one; SCEVExpander
     14 ; should determine that the old one is good to reuse.
     15 
     16 entry:
     17   %res = alloca i32, align 4
     18   store volatile i32 0, i32* %res, align 4
     19   %call = call i32 @fn()
     20   br label %for.cond
     21 
     22 for.cond:                                         ; preds = %for.inc6, %entry
     23   %i.0 = phi i32 [ 0, %entry ], [ %inc7, %for.inc6 ]
     24   %cmp = icmp slt i32 %i.0, %call
     25   br i1 %cmp, label %for.body, label %for.cond.cleanup
     26 
     27 for.cond.cleanup:                                 ; preds = %for.cond
     28   br label %for.end8
     29 
     30 for.body:                                         ; preds = %for.cond
     31   br label %for.cond1
     32 
     33 for.cond1:                                        ; preds = %for.inc, %for.body
     34   %j.0 = phi i32 [ 0, %for.body ], [ %inc5, %for.inc ]
     35   %cmp2 = icmp slt i32 %j.0, %i.0
     36   br i1 %cmp2, label %for.body4, label %for.cond.cleanup3
     37 
     38 for.cond.cleanup3:                                ; preds = %for.cond1
     39   br label %for.end
     40 
     41 for.body4:                                        ; preds = %for.cond1
     42   %0 = load volatile i32, i32* %res, align 4
     43   %inc = add nsw i32 %0, 1
     44   store volatile i32 %inc, i32* %res, align 4
     45   br label %for.inc
     46 
     47 for.inc:                                          ; preds = %for.body4
     48   %inc5 = add nsw i32 %j.0, 1
     49   br label %for.cond1
     50 
     51 for.end:                                          ; preds = %for.cond.cleanup3
     52   br label %for.inc6
     53 
     54 for.inc6:                                         ; preds = %for.end
     55   %inc7 = add nsw i32 %i.0, 1
     56   br label %for.cond
     57 
     58 for.end8:                                         ; preds = %for.cond.cleanup
     59   %1 = load volatile i32, i32* %res, align 4
     60   %cmp9 = icmp eq i32 %1, 45
     61   %conv = zext i1 %cmp9 to i32
     62   ret i32 %conv
     63 }
     64