1 ; RUN: opt < %s -loop-unroll -S -unroll-count=4 | FileCheck %s 2 ; Test phi update after partial unroll. 3 4 declare i1 @check() nounwind 5 6 ; CHECK: @test 7 ; CHECK: if.else: 8 ; CHECK: if.then.loopexit 9 ; CHECK: %sub5.lcssa = phi i32 [ %sub{{.*}}, %if.else{{.*}} ], [ %sub{{.*}}, %if.else{{.*}} ], [ %sub{{.*}}, %if.else{{.*}} ], [ %sub{{.*}}, %if.else{{.*}} ] 10 ; CHECK: if.else.3 11 define void @test1(i32 %i, i32 %j) nounwind uwtable ssp { 12 entry: 13 %cond1 = call zeroext i1 @check() 14 br i1 %cond1, label %if.then, label %if.else.lr.ph 15 16 if.else.lr.ph: ; preds = %entry 17 br label %if.else 18 19 if.else: ; preds = %if.else, %if.else.lr.ph 20 %sub = phi i32 [ %i, %if.else.lr.ph ], [ %sub5, %if.else ] 21 %sub5 = sub i32 %sub, %j 22 %cond2 = call zeroext i1 @check() 23 br i1 %cond2, label %if.then, label %if.else 24 25 if.then: ; preds = %if.else, %entry 26 %i.tr = phi i32 [ %i, %entry ], [ %sub5, %if.else ] 27 ret void 28 29 } 30 31 ; PR7318: assertion failure after doing a simple loop unroll 32 ; 33 ; CHECK-LABEL: @test2( 34 ; CHECK: bb1.bb2_crit_edge: 35 ; CHECK: %.lcssa = phi i32 [ %{{[2468]}}, %bb1{{.*}} ], [ %{{[2468]}}, %bb1{{.*}} ], [ %{{[2468]}}, %bb1{{.*}} ], [ %{{[2468]}}, %bb1{{.*}} ] 36 ; CHECK: bb1.3: 37 define i32 @test2(i32* nocapture %p, i32 %n) nounwind readonly { 38 entry: 39 %0 = icmp sgt i32 %n, 0 ; <i1> [#uses=1] 40 br i1 %0, label %bb.nph, label %bb2 41 42 bb.nph: ; preds = %entry 43 %tmp = zext i32 %n to i64 ; <i64> [#uses=1] 44 br label %bb 45 46 bb: ; preds = %bb.nph, %bb1 47 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %bb1 ] ; <i64> [#uses=2] 48 %s.01 = phi i32 [ 0, %bb.nph ], [ %2, %bb1 ] ; <i32> [#uses=1] 49 %scevgep = getelementptr i32* %p, i64 %indvar ; <i32*> [#uses=1] 50 %1 = load i32* %scevgep, align 1 ; <i32> [#uses=1] 51 %2 = add nsw i32 %1, %s.01 ; <i32> [#uses=2] 52 br label %bb1 53 54 bb1: ; preds = %bb 55 %indvar.next = add i64 %indvar, 1 ; <i64> [#uses=2] 56 %exitcond = icmp ne i64 %indvar.next, %tmp ; <i1> [#uses=1] 57 br i1 %exitcond, label %bb, label %bb1.bb2_crit_edge 58 59 bb1.bb2_crit_edge: ; preds = %bb1 60 %.lcssa = phi i32 [ %2, %bb1 ] ; <i32> [#uses=1] 61 br label %bb2 62 63 bb2: ; preds = %bb1.bb2_crit_edge, %entry 64 %s.0.lcssa = phi i32 [ %.lcssa, %bb1.bb2_crit_edge ], [ 0, %entry ] ; <i32> [#uses=1] 65 ret i32 %s.0.lcssa 66 } 67 68 ; Check phi update for loop with an early-exit. 69 ; 70 ; CHECK-LABEL: @test3( 71 ; CHECK: return.loopexit: 72 ; CHECK: %tmp7.i.lcssa = phi i32 [ %tmp7.i{{.*}}, %land.lhs.true{{.*}} ], [ %tmp7.i{{.*}}, %land.lhs.true{{.*}} ], [ %tmp7.i{{.*}}, %land.lhs.true{{.*}} ], [ %tmp7.i{{.*}}, %land.lhs.true{{.*}} ] 73 ; CHECK: exit.3: 74 define i32 @test3() nounwind uwtable ssp align 2 { 75 entry: 76 %cond1 = call zeroext i1 @check() 77 br i1 %cond1, label %return, label %if.end 78 79 if.end: ; preds = %entry 80 br label %do.body 81 82 do.body: ; preds = %do.cond, %if.end 83 %cond2 = call zeroext i1 @check() 84 br i1 %cond2, label %exit, label %do.cond 85 86 exit: ; preds = %do.body 87 %tmp7.i = load i32* undef, align 8 88 br i1 undef, label %do.cond, label %land.lhs.true 89 90 land.lhs.true: ; preds = %exit 91 br i1 undef, label %return, label %do.cond 92 93 do.cond: ; preds = %land.lhs.true, %exit, %do.body 94 %cond3 = call zeroext i1 @check() 95 br i1 %cond3, label %do.end, label %do.body 96 97 do.end: ; preds = %do.cond 98 br label %return 99 100 return: ; preds = %do.end, %land.lhs.true, %entry 101 %retval.0 = phi i32 [ 0, %do.end ], [ 0, %entry ], [ %tmp7.i, %land.lhs.true ] 102 ret i32 %retval.0 103 } 104