1 ; RUN: opt < %s -loop-unroll -S -unroll-count=4 | FileCheck %s
2 ; Test phi update after partial unroll.
4 declare i1 @check() nounwind
8 ; CHECK: if.then.loopexit
9 ; CHECK: %sub5.lcssa = phi i32 [ %sub{{.*}}, %if.else{{.*}} ], [ %sub{{.*}}, %if.else{{.*}} ], [ %sub{{.*}}, %if.else{{.*}} ], [ %sub{{.*}}, %if.else{{.*}} ]
11 define void @test1(i32 %i, i32 %j) nounwind uwtable ssp {
13 %cond1 = call zeroext i1 @check()
14 br i1 %cond1, label %if.then, label %if.else.lr.ph
16 if.else.lr.ph: ; preds = %entry
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
25 if.then: ; preds = %if.else, %entry
26 %i.tr = phi i32 [ %i, %entry ], [ %sub5, %if.else ]
31 ; PR7318: assertion failure after doing a simple loop unroll
33 ; CHECK-LABEL: @test2(
34 ; CHECK: bb1.bb2_crit_edge:
35 ; CHECK: %.lcssa = phi i32 [ %{{[2468]}}, %bb1{{.*}} ], [ %{{[2468]}}, %bb1{{.*}} ], [ %{{[2468]}}, %bb1{{.*}} ], [ %{{[2468]}}, %bb1{{.*}} ]
37 define i32 @test2(i32* nocapture %p, i32 %n) nounwind readonly {
39 %0 = icmp sgt i32 %n, 0 ; <i1> [#uses=1]
40 br i1 %0, label %bb.nph, label %bb2
42 bb.nph: ; preds = %entry
43 %tmp = zext i32 %n to i64 ; <i64> [#uses=1]
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, i32* %p, i64 %indvar ; <i32*> [#uses=1]
50 %1 = load i32, i32* %scevgep, align 1 ; <i32> [#uses=1]
51 %2 = add nsw i32 %1, %s.01 ; <i32> [#uses=2]
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
59 bb1.bb2_crit_edge: ; preds = %bb1
60 %.lcssa = phi i32 [ %2, %bb1 ] ; <i32> [#uses=1]
63 bb2: ; preds = %bb1.bb2_crit_edge, %entry
64 %s.0.lcssa = phi i32 [ %.lcssa, %bb1.bb2_crit_edge ], [ 0, %entry ] ; <i32> [#uses=1]
68 ; Check phi update for loop with an early-exit.
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{{.*}} ]
74 define i32 @test3() nounwind uwtable ssp align 2 {
76 %cond1 = call zeroext i1 @check()
77 br i1 %cond1, label %return, label %if.end
79 if.end: ; preds = %entry
82 do.body: ; preds = %do.cond, %if.end
83 %cond2 = call zeroext i1 @check()
84 br i1 %cond2, label %exit, label %do.cond
86 exit: ; preds = %do.body
87 %tmp7.i = load i32, i32* undef, align 8
88 br i1 undef, label %do.cond, label %land.lhs.true
90 land.lhs.true: ; preds = %exit
91 br i1 undef, label %return, label %do.cond
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
97 do.end: ; preds = %do.cond
100 return: ; preds = %do.end, %land.lhs.true, %entry
101 %retval.0 = phi i32 [ 0, %do.end ], [ 0, %entry ], [ %tmp7.i, %land.lhs.true ]