1 ; RUN: opt -S < %s -passes='print<scalar-evolution>,loop-simplify,print<scalar-evolution>' 2>&1 | FileCheck %s
3 ; Provide legal integer types.
4 target datalayout = "n8:16:32:64"
6 @maxStat = external global i32
8 ; LoopSimplify should invalidate SCEV when splitting out the
12 ; CHECK-LABEL: Classifying expressions for: @test
13 ; CHECK: %[[PHI:.*]] = phi i32 [ 0, %entry ], [ %{{.*}}, %if.then5 ], [ %[[PHI]], %if.end ]
14 ; CHECK-LABEL: Determining loop execution counts for: @test
15 ; CHECK: Loop %for.body18: Unpredictable backedge-taken count.
16 ; CHECK: Loop %for.body18: constant max backedge-taken count is i32 2147483646
17 ; CHECK: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count.
18 ; CHECK: Loop %for.cond: Unpredictable constant max backedge-taken count.
20 ; Now simplify the loop, which should cause SCEV to re-compute more precise
21 ; info here in addition to having preheader PHIs. Second SCEV print:
22 ; CHECK-LABEL: Classifying expressions for: @test
23 ; CHECK: phi i32 [ %{{.*}}, %if.then5 ], [ 0, %entry ]
24 ; CHECK-LABEL: Determining loop execution counts for: @test
25 ; CHECK: Loop %for.body18: Unpredictable backedge-taken count.
26 ; CHECK: Loop %for.body18: constant max backedge-taken count is i32 2147483646
27 ; CHECK: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count.
28 ; CHECK: Loop %for.cond: constant max backedge-taken count is i32 -2147483647
29 ; CHECK: Loop %for.cond.outer: <multiple exits> Unpredictable backedge-taken count.
30 ; CHECK: Loop %for.cond.outer: Unpredictable constant max backedge-taken count.
31 define i32 @test() nounwind {
35 for.cond: ; preds = %if.then5, %if.end, %entry
36 %cuts.1 = phi i32 [ 0, %entry ], [ %inc, %if.then5 ], [ %cuts.1, %if.end ]
37 %0 = phi i32 [ 0, %entry ], [ %add, %if.end ], [ %add, %if.then5 ]
39 %cmp = icmp slt i32 %0, 1
40 %tmp1 = load i32, ptr @maxStat, align 4
41 br i1 %cmp, label %for.body, label %for.cond14.preheader
43 for.cond14.preheader: ; preds = %for.cond
44 %cmp1726 = icmp sgt i32 %tmp1, 0
45 br i1 %cmp1726, label %for.body18, label %return
47 for.body: ; preds = %for.cond
48 %cmp2 = icmp sgt i32 %tmp1, 100
49 br i1 %cmp2, label %return, label %if.end
51 if.end: ; preds = %for.body
52 %cmp4 = icmp sgt i32 %tmp1, -1
53 br i1 %cmp4, label %if.then5, label %for.cond
55 if.then5: ; preds = %if.end
56 call void @foo() nounwind
57 %inc = add i32 %cuts.1, 1
60 for.body18: ; preds = %for.body18, %for.cond14.preheader
61 %i13.027 = phi i32 [ %1, %for.body18 ], [ 0, %for.cond14.preheader ]
62 call void @foo() nounwind
63 %1 = add nsw i32 %i13.027, 1
64 %tmp16 = load i32, ptr @maxStat, align 4
65 %cmp17 = icmp slt i32 %1, %tmp16
66 br i1 %cmp17, label %for.body18, label %return
68 return: ; preds = %for.body18, %for.body, %for.cond14.preheader
72 declare void @foo() nounwind
74 ; Notify SCEV when removing an ExitingBlock. This only changes the
75 ; backedge-taken information.
78 ; CHECK-LABEL: Determining loop execution counts for: @mergeExit
79 ; CHECK: Loop %while.cond191: <multiple exits> Unpredictable backedge-taken count.
80 ; CHECK: Loop %while.cond191: constant max backedge-taken count is i32 -1
81 ; CHECK: Loop %while.cond191.outer: <multiple exits> Unpredictable backedge-taken count.
82 ; CHECK: Loop %while.cond191.outer: Unpredictable constant max backedge-taken count.
84 ; After simplifying, the max backedge count is refined.
86 ; CHECK-LABEL: Determining loop execution counts for: @mergeExit
87 ; CHECK: Loop %while.cond191: <multiple exits> backedge-taken count is i32 0
88 ; CHECK: Loop %while.cond191: constant max backedge-taken count is i32 0
89 ; CHECK: Loop %while.cond191.outer: <multiple exits> Unpredictable backedge-taken count.
90 ; CHECK: Loop %while.cond191.outer: constant max backedge-taken count is i1 false
91 define void @mergeExit(i32 %MapAttrCount) nounwind uwtable ssp {
93 br i1 undef, label %if.then124, label %if.end126
95 if.then124: ; preds = %entry
98 if.end126: ; preds = %entry
99 br i1 undef, label %while.body.lr.ph, label %if.end591
101 while.body.lr.ph: ; preds = %if.end126
102 br i1 undef, label %if.end140, label %if.then137
104 if.then137: ; preds = %while.body.lr.ph
107 if.end140: ; preds = %while.body.lr.ph
108 br i1 undef, label %while.cond191.outer, label %if.then148
110 if.then148: ; preds = %if.end140
113 while.cond191.outer: ; preds = %if.then205, %if.end140
114 br label %while.cond191
116 while.cond191: ; preds = %while.body197, %while.cond191.outer
117 %CppIndex.0 = phi i32 [ %inc, %while.body197 ], [ undef, %while.cond191.outer ]
118 br i1 undef, label %land.rhs, label %if.then216
120 land.rhs: ; preds = %while.cond191
121 %inc = add i32 %CppIndex.0, 1
122 %cmp196 = icmp ult i32 %inc, %MapAttrCount
123 br i1 %cmp196, label %while.body197, label %if.then216
125 while.body197: ; preds = %land.rhs
126 br i1 undef, label %if.then205, label %while.cond191
128 if.then205: ; preds = %while.body197
129 br label %while.cond191.outer
131 if.then216: ; preds = %land.rhs, %while.cond191
132 br i1 undef, label %if.else, label %if.then221
134 if.then221: ; preds = %if.then216
137 if.else: ; preds = %if.then216
138 br i1 undef, label %if.then266, label %if.end340
140 if.then266: ; preds = %if.else
141 switch i32 undef, label %if.else329 [
142 i32 17, label %if.then285
143 i32 19, label %if.then285
144 i32 18, label %if.then285
145 i32 15, label %if.then285
148 if.then285: ; preds = %if.then266, %if.then266, %if.then266, %if.then266
149 br i1 undef, label %if.then317, label %if.else324
151 if.then317: ; preds = %if.then285
154 if.else324: ; preds = %if.then285
157 if.else329: ; preds = %if.then266
160 if.end340: ; preds = %if.then317, %if.else
163 if.end591: ; preds = %if.end126
164 br i1 undef, label %cond.end, label %cond.false
166 cond.false: ; preds = %if.end591
169 cond.end: ; preds = %if.end591