blob: 07486ef246861e8d14c9a9701783ba018eef2f6b [file] [log] [blame]
Eric Christophercee313d2019-04-17 04:52:47 +00001; RUN: opt -S < %s -analyze -scalar-evolution -loop-simplify -scalar-evolution | FileCheck %s
2
3; Provide legal integer types.
4target datalayout = "n8:16:32:64"
5
6@maxStat = external global i32
7
8; LoopSimplify should invalidate SCEV when splitting out the
9; inner loop.
10;
11; First SCEV print:
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: max backedge-taken count is 2147483646
17; CHECK: Loop %for.body18: Unpredictable predicated backedge-taken count.
18; CHECK: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count.
19; CHECK: Loop %for.cond: Unpredictable max backedge-taken count.
20; CHECK: Loop %for.cond: Unpredictable predicated backedge-taken count.
21;
22; Now simplify the loop, which should cause SCEV to re-compute more precise
23; info here in addition to having preheader PHIs. Second SCEV print:
24; CHECK-LABEL: Classifying expressions for: @test
25; CHECK: phi i32 [ %{{.*}}, %if.then5 ], [ 0, %entry ]
26; CHECK-LABEL: Determining loop execution counts for: @test
27; CHECK: Loop %for.body18: Unpredictable backedge-taken count.
28; CHECK: Loop %for.body18: max backedge-taken count is 2147483646
29; CHECK: Loop %for.body18: Unpredictable predicated backedge-taken count.
30; CHECK: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count.
31; CHECK: Loop %for.cond: max backedge-taken count is -2147483647
32; CHECK: Loop %for.cond: Unpredictable predicated backedge-taken count.
33; CHECK: Loop %for.cond.outer: <multiple exits> Unpredictable backedge-taken count.
34; CHECK: Loop %for.cond.outer: Unpredictable max backedge-taken count.
35; CHECK: Loop %for.cond.outer: Unpredictable predicated backedge-taken count.
36define i32 @test() nounwind {
37entry:
38 br label %for.cond
39
40for.cond: ; preds = %if.then5, %if.end, %entry
41 %cuts.1 = phi i32 [ 0, %entry ], [ %inc, %if.then5 ], [ %cuts.1, %if.end ]
42 %0 = phi i32 [ 0, %entry ], [ %add, %if.end ], [ %add, %if.then5 ]
43 %add = add i32 %0, 1
44 %cmp = icmp slt i32 %0, 1
45 %tmp1 = load i32, i32* @maxStat, align 4
46 br i1 %cmp, label %for.body, label %for.cond14.preheader
47
48for.cond14.preheader: ; preds = %for.cond
49 %cmp1726 = icmp sgt i32 %tmp1, 0
50 br i1 %cmp1726, label %for.body18, label %return
51
52for.body: ; preds = %for.cond
53 %cmp2 = icmp sgt i32 %tmp1, 100
54 br i1 %cmp2, label %return, label %if.end
55
56if.end: ; preds = %for.body
57 %cmp4 = icmp sgt i32 %tmp1, -1
58 br i1 %cmp4, label %if.then5, label %for.cond
59
60if.then5: ; preds = %if.end
61 call void @foo() nounwind
62 %inc = add i32 %cuts.1, 1
63 br label %for.cond
64
65for.body18: ; preds = %for.body18, %for.cond14.preheader
66 %i13.027 = phi i32 [ %1, %for.body18 ], [ 0, %for.cond14.preheader ]
67 call void @foo() nounwind
68 %1 = add nsw i32 %i13.027, 1
69 %tmp16 = load i32, i32* @maxStat, align 4
70 %cmp17 = icmp slt i32 %1, %tmp16
71 br i1 %cmp17, label %for.body18, label %return
72
73return: ; preds = %for.body18, %for.body, %for.cond14.preheader
74 ret i32 0
75}
76
77declare void @foo() nounwind
78
79; Notify SCEV when removing an ExitingBlock. This only changes the
80; backedge-taken information.
81;
82; First SCEV print:
83; CHECK-LABEL: Determining loop execution counts for: @mergeExit
84; CHECK: Loop %while.cond191: <multiple exits> Unpredictable backedge-taken count.
85; CHECK: Loop %while.cond191: max backedge-taken count is -1
86; CHECK: Loop %while.cond191: Unpredictable predicated backedge-taken count.
87; CHECK: Loop %while.cond191.outer: <multiple exits> Unpredictable backedge-taken count.
88; CHECK: Loop %while.cond191.outer: Unpredictable max backedge-taken count.
89; CHECK: Loop %while.cond191.outer: Unpredictable predicated backedge-taken count.
90;
91; After simplifying, the max backedge count is refined.
92; Second SCEV print:
93; CHECK-LABEL: Determining loop execution counts for: @mergeExit
94; CHECK: Loop %while.cond191: <multiple exits> backedge-taken count is 0
95; CHECK: Loop %while.cond191: max backedge-taken count is 0
96; CHECK: Loop %while.cond191: Predicated backedge-taken count is 0
97; CHECK: Loop %while.cond191.outer: <multiple exits> Unpredictable backedge-taken count.
98; CHECK: Loop %while.cond191.outer: max backedge-taken count is false
99; CHECK: Loop %while.cond191.outer: Unpredictable predicated backedge-taken count.
100define void @mergeExit(i32 %MapAttrCount) nounwind uwtable ssp {
101entry:
102 br i1 undef, label %if.then124, label %if.end126
103
104if.then124: ; preds = %entry
105 unreachable
106
107if.end126: ; preds = %entry
108 br i1 undef, label %while.body.lr.ph, label %if.end591
109
110while.body.lr.ph: ; preds = %if.end126
111 br i1 undef, label %if.end140, label %if.then137
112
113if.then137: ; preds = %while.body.lr.ph
114 unreachable
115
116if.end140: ; preds = %while.body.lr.ph
117 br i1 undef, label %while.cond191.outer, label %if.then148
118
119if.then148: ; preds = %if.end140
120 unreachable
121
122while.cond191.outer: ; preds = %if.then205, %if.end140
123 br label %while.cond191
124
125while.cond191: ; preds = %while.body197, %while.cond191.outer
126 %CppIndex.0 = phi i32 [ %inc, %while.body197 ], [ undef, %while.cond191.outer ]
127 br i1 undef, label %land.rhs, label %if.then216
128
129land.rhs: ; preds = %while.cond191
130 %inc = add i32 %CppIndex.0, 1
131 %cmp196 = icmp ult i32 %inc, %MapAttrCount
132 br i1 %cmp196, label %while.body197, label %if.then216
133
134while.body197: ; preds = %land.rhs
135 br i1 undef, label %if.then205, label %while.cond191
136
137if.then205: ; preds = %while.body197
138 br label %while.cond191.outer
139
140if.then216: ; preds = %land.rhs, %while.cond191
141 br i1 undef, label %if.else, label %if.then221
142
143if.then221: ; preds = %if.then216
144 unreachable
145
146if.else: ; preds = %if.then216
147 br i1 undef, label %if.then266, label %if.end340
148
149if.then266: ; preds = %if.else
150 switch i32 undef, label %if.else329 [
151 i32 17, label %if.then285
152 i32 19, label %if.then285
153 i32 18, label %if.then285
154 i32 15, label %if.then285
155 ]
156
157if.then285: ; preds = %if.then266, %if.then266, %if.then266, %if.then266
158 br i1 undef, label %if.then317, label %if.else324
159
160if.then317: ; preds = %if.then285
161 br label %if.end340
162
163if.else324: ; preds = %if.then285
164 unreachable
165
166if.else329: ; preds = %if.then266
167 unreachable
168
169if.end340: ; preds = %if.then317, %if.else
170 unreachable
171
172if.end591: ; preds = %if.end126
173 br i1 undef, label %cond.end, label %cond.false
174
175cond.false: ; preds = %if.end591
176 unreachable
177
178cond.end: ; preds = %if.end591
179 ret void
180}