1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
3 ; RUN: opt < %s -S -passes='loop-simplify,loop(loop-flatten),dce,verify' -loop-flatten-widen-iv=true \
4 ; RUN: -verify-loop-info -verify-dom-info -verify-scev \
5 ; RUN: -loop-flatten-cost-threshold=6 | \
6 ; RUN: FileCheck %s --check-prefix=CHECK
8 ; RUN: opt < %s -S -passes='loop-simplify,loop(loop-flatten),dce,verify' -loop-flatten-widen-iv=false \
9 ; RUN: -verify-loop-info -verify-dom-info -verify-scev | \
10 ; RUN: FileCheck %s --check-prefix=DONTWIDEN
12 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
14 ; DONTWIDEN-NOT: %flatten.tripcount
15 ; DONTWIDEN-NOT: %flatten.trunciv
17 ; Function Attrs: nounwind
18 define void @foo(ptr %A, i32 %N, i32 %M) {
21 ; CHECK-NEXT: [[CMP17:%.*]] = icmp sgt i32 [[N:%.*]], 0
22 ; CHECK-NEXT: br i1 [[CMP17]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]], label [[FOR_COND_CLEANUP:%.*]]
23 ; CHECK: for.cond1.preheader.lr.ph:
24 ; CHECK-NEXT: [[CMP215:%.*]] = icmp sgt i32 [[M:%.*]], 0
25 ; CHECK-NEXT: br i1 [[CMP215]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]], label [[FOR_COND_CLEANUP]]
26 ; CHECK: for.cond1.preheader.us.preheader:
27 ; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[M]] to i64
28 ; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[N]] to i64
29 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 [[TMP0]], [[TMP1]]
30 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
31 ; CHECK: for.cond1.preheader.us:
32 ; CHECK-NEXT: [[INDVAR1:%.*]] = phi i64 [ [[INDVAR_NEXT2:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
33 ; CHECK-NEXT: [[FLATTEN_TRUNCIV:%.*]] = trunc i64 [[INDVAR1]] to i32
34 ; CHECK-NEXT: br label [[FOR_BODY4_US:%.*]]
35 ; CHECK: for.body4.us:
36 ; CHECK-NEXT: [[IDXPROM_US:%.*]] = sext i32 [[FLATTEN_TRUNCIV]] to i64
37 ; CHECK-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[IDXPROM_US]]
38 ; CHECK-NEXT: tail call void @f(ptr [[ARRAYIDX_US]])
39 ; CHECK-NEXT: br label [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US]]
40 ; CHECK: for.cond1.for.cond.cleanup3_crit_edge.us:
41 ; CHECK-NEXT: [[INDVAR_NEXT2]] = add i64 [[INDVAR1]], 1
42 ; CHECK-NEXT: [[CMP_US:%.*]] = icmp slt i64 [[INDVAR_NEXT2]], [[FLATTEN_TRIPCOUNT]]
43 ; CHECK-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
44 ; CHECK: for.cond.cleanup.loopexit:
45 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
46 ; CHECK: for.cond.cleanup:
47 ; CHECK-NEXT: ret void
49 ; DONTWIDEN-LABEL: @foo(
50 ; DONTWIDEN-NEXT: entry:
51 ; DONTWIDEN-NEXT: [[CMP17:%.*]] = icmp sgt i32 [[N:%.*]], 0
52 ; DONTWIDEN-NEXT: br i1 [[CMP17]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]], label [[FOR_COND_CLEANUP:%.*]]
53 ; DONTWIDEN: for.cond1.preheader.lr.ph:
54 ; DONTWIDEN-NEXT: [[CMP215:%.*]] = icmp sgt i32 [[M:%.*]], 0
55 ; DONTWIDEN-NEXT: br i1 [[CMP215]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]], label [[FOR_COND_CLEANUP]]
56 ; DONTWIDEN: for.cond1.preheader.us.preheader:
57 ; DONTWIDEN-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
58 ; DONTWIDEN: for.cond1.preheader.us:
59 ; DONTWIDEN-NEXT: [[I_018_US:%.*]] = phi i32 [ [[INC6_US:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
60 ; DONTWIDEN-NEXT: [[MUL_US:%.*]] = mul nsw i32 [[I_018_US]], [[M]]
61 ; DONTWIDEN-NEXT: br label [[FOR_BODY4_US:%.*]]
62 ; DONTWIDEN: for.body4.us:
63 ; DONTWIDEN-NEXT: [[J_016_US:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_US]] ], [ [[INC_US:%.*]], [[FOR_BODY4_US]] ]
64 ; DONTWIDEN-NEXT: [[ADD_US:%.*]] = add nsw i32 [[J_016_US]], [[MUL_US]]
65 ; DONTWIDEN-NEXT: [[IDXPROM_US:%.*]] = sext i32 [[ADD_US]] to i64
66 ; DONTWIDEN-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[IDXPROM_US]]
67 ; DONTWIDEN-NEXT: tail call void @f(ptr [[ARRAYIDX_US]])
68 ; DONTWIDEN-NEXT: [[INC_US]] = add nuw nsw i32 [[J_016_US]], 1
69 ; DONTWIDEN-NEXT: [[CMP2_US:%.*]] = icmp slt i32 [[INC_US]], [[M]]
70 ; DONTWIDEN-NEXT: br i1 [[CMP2_US]], label [[FOR_BODY4_US]], label [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US]]
71 ; DONTWIDEN: for.cond1.for.cond.cleanup3_crit_edge.us:
72 ; DONTWIDEN-NEXT: [[INC6_US]] = add nuw nsw i32 [[I_018_US]], 1
73 ; DONTWIDEN-NEXT: [[CMP_US:%.*]] = icmp slt i32 [[INC6_US]], [[N]]
74 ; DONTWIDEN-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
75 ; DONTWIDEN: for.cond.cleanup.loopexit:
76 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
77 ; DONTWIDEN: for.cond.cleanup:
78 ; DONTWIDEN-NEXT: ret void
81 %cmp17 = icmp sgt i32 %N, 0
82 br i1 %cmp17, label %for.cond1.preheader.lr.ph, label %for.cond.cleanup
84 for.cond1.preheader.lr.ph:
85 %cmp215 = icmp sgt i32 %M, 0
86 br i1 %cmp215, label %for.cond1.preheader.us.preheader, label %for.cond.cleanup
88 for.cond1.preheader.us.preheader:
89 br label %for.cond1.preheader.us
91 for.cond1.preheader.us:
92 %i.018.us = phi i32 [ %inc6.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ]
93 %mul.us = mul nsw i32 %i.018.us, %M
94 br label %for.body4.us
97 %j.016.us = phi i32 [ 0, %for.cond1.preheader.us ], [ %inc.us, %for.body4.us ]
98 %add.us = add nsw i32 %j.016.us, %mul.us
99 %idxprom.us = sext i32 %add.us to i64
100 %arrayidx.us = getelementptr inbounds i32, ptr %A, i64 %idxprom.us
101 tail call void @f(ptr %arrayidx.us) #2
102 %inc.us = add nuw nsw i32 %j.016.us, 1
103 %cmp2.us = icmp slt i32 %inc.us, %M
104 br i1 %cmp2.us, label %for.body4.us, label %for.cond1.for.cond.cleanup3_crit_edge.us
106 for.cond1.for.cond.cleanup3_crit_edge.us:
107 %inc6.us = add nuw nsw i32 %i.018.us, 1
108 %cmp.us = icmp slt i32 %inc6.us, %N
109 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.cond.cleanup
115 ; This test case corresponds to this input:
117 ; for (int i = 0; i < N; ++i)
118 ; for (int j = 0; j < M; ++j)
121 ; It is very similar to test case @foo above, but the CFG is slightly
122 ; different, making the analysis slightly different.
124 define void @foo2_sext(i32* nocapture readonly %A, i32 %N, i32 %M) {
125 ; CHECK-LABEL: @foo2_sext(
127 ; CHECK-NEXT: [[CMP17:%.*]] = icmp sgt i32 [[N:%.*]], 0
128 ; CHECK-NEXT: br i1 [[CMP17]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]], label [[FOR_COND_CLEANUP:%.*]]
129 ; CHECK: for.cond1.preheader.lr.ph:
130 ; CHECK-NEXT: [[CMP215:%.*]] = icmp sgt i32 [[M:%.*]], 0
131 ; CHECK-NEXT: br i1 [[CMP215]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]], label [[FOR_COND1_PREHEADER_PREHEADER:%.*]]
132 ; CHECK: for.cond1.preheader.preheader:
133 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER:%.*]]
134 ; CHECK: for.cond1.preheader.us.preheader:
135 ; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[M]] to i64
136 ; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[N]] to i64
137 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 [[TMP0]], [[TMP1]]
138 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
139 ; CHECK: for.cond1.preheader.us:
140 ; CHECK-NEXT: [[INDVAR2:%.*]] = phi i64 [ [[INDVAR_NEXT3:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
141 ; CHECK-NEXT: [[I_018_US:%.*]] = phi i32 [ [[INC6_US:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
142 ; CHECK-NEXT: br label [[FOR_BODY4_US:%.*]]
143 ; CHECK: for.body4.us:
144 ; CHECK-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[INDVAR2]]
145 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX_US]], align 4
146 ; CHECK-NEXT: tail call void @g(i32 [[TMP2]])
147 ; CHECK-NEXT: br label [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US]]
148 ; CHECK: for.cond1.for.cond.cleanup3_crit_edge.us:
149 ; CHECK-NEXT: [[INDVAR_NEXT3]] = add i64 [[INDVAR2]], 1
150 ; CHECK-NEXT: [[INC6_US]] = add nuw nsw i32 [[I_018_US]], 1
151 ; CHECK-NEXT: [[CMP_US:%.*]] = icmp slt i64 [[INDVAR_NEXT3]], [[FLATTEN_TRIPCOUNT]]
152 ; CHECK-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
153 ; CHECK: for.cond1.preheader:
154 ; CHECK-NEXT: [[I_018:%.*]] = phi i32 [ [[INC6:%.*]], [[FOR_COND1_PREHEADER]] ], [ 0, [[FOR_COND1_PREHEADER_PREHEADER]] ]
155 ; CHECK-NEXT: [[INC6]] = add nuw nsw i32 [[I_018]], 1
156 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC6]], [[N]]
157 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_COND1_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT19:%.*]]
158 ; CHECK: for.cond.cleanup.loopexit:
159 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
160 ; CHECK: for.cond.cleanup.loopexit19:
161 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
162 ; CHECK: for.cond.cleanup:
163 ; CHECK-NEXT: ret void
165 ; DONTWIDEN-LABEL: @foo2_sext(
166 ; DONTWIDEN-NEXT: entry:
167 ; DONTWIDEN-NEXT: [[CMP17:%.*]] = icmp sgt i32 [[N:%.*]], 0
168 ; DONTWIDEN-NEXT: br i1 [[CMP17]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]], label [[FOR_COND_CLEANUP:%.*]]
169 ; DONTWIDEN: for.cond1.preheader.lr.ph:
170 ; DONTWIDEN-NEXT: [[CMP215:%.*]] = icmp sgt i32 [[M:%.*]], 0
171 ; DONTWIDEN-NEXT: br i1 [[CMP215]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]], label [[FOR_COND1_PREHEADER_PREHEADER:%.*]]
172 ; DONTWIDEN: for.cond1.preheader.preheader:
173 ; DONTWIDEN-NEXT: br label [[FOR_COND1_PREHEADER:%.*]]
174 ; DONTWIDEN: for.cond1.preheader.us.preheader:
175 ; DONTWIDEN-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
176 ; DONTWIDEN: for.cond1.preheader.us:
177 ; DONTWIDEN-NEXT: [[I_018_US:%.*]] = phi i32 [ [[INC6_US:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
178 ; DONTWIDEN-NEXT: [[MUL_US:%.*]] = mul nsw i32 [[I_018_US]], [[M]]
179 ; DONTWIDEN-NEXT: br label [[FOR_BODY4_US:%.*]]
180 ; DONTWIDEN: for.body4.us:
181 ; DONTWIDEN-NEXT: [[J_016_US:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_US]] ], [ [[INC_US:%.*]], [[FOR_BODY4_US]] ]
182 ; DONTWIDEN-NEXT: [[ADD_US:%.*]] = add nsw i32 [[J_016_US]], [[MUL_US]]
183 ; DONTWIDEN-NEXT: [[IDXPROM_US:%.*]] = sext i32 [[ADD_US]] to i64
184 ; DONTWIDEN-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[IDXPROM_US]]
185 ; DONTWIDEN-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX_US]], align 4
186 ; DONTWIDEN-NEXT: tail call void @g(i32 [[TMP0]])
187 ; DONTWIDEN-NEXT: [[INC_US]] = add nuw nsw i32 [[J_016_US]], 1
188 ; DONTWIDEN-NEXT: [[CMP2_US:%.*]] = icmp slt i32 [[INC_US]], [[M]]
189 ; DONTWIDEN-NEXT: br i1 [[CMP2_US]], label [[FOR_BODY4_US]], label [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US]]
190 ; DONTWIDEN: for.cond1.for.cond.cleanup3_crit_edge.us:
191 ; DONTWIDEN-NEXT: [[INC6_US]] = add nuw nsw i32 [[I_018_US]], 1
192 ; DONTWIDEN-NEXT: [[CMP_US:%.*]] = icmp slt i32 [[INC6_US]], [[N]]
193 ; DONTWIDEN-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
194 ; DONTWIDEN: for.cond1.preheader:
195 ; DONTWIDEN-NEXT: [[I_018:%.*]] = phi i32 [ [[INC6:%.*]], [[FOR_COND1_PREHEADER]] ], [ 0, [[FOR_COND1_PREHEADER_PREHEADER]] ]
196 ; DONTWIDEN-NEXT: [[INC6]] = add nuw nsw i32 [[I_018]], 1
197 ; DONTWIDEN-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC6]], [[N]]
198 ; DONTWIDEN-NEXT: br i1 [[CMP]], label [[FOR_COND1_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT19:%.*]]
199 ; DONTWIDEN: for.cond.cleanup.loopexit:
200 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
201 ; DONTWIDEN: for.cond.cleanup.loopexit19:
202 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
203 ; DONTWIDEN: for.cond.cleanup:
204 ; DONTWIDEN-NEXT: ret void
207 %cmp17 = icmp sgt i32 %N, 0
208 br i1 %cmp17, label %for.cond1.preheader.lr.ph, label %for.cond.cleanup
210 for.cond1.preheader.lr.ph:
211 %cmp215 = icmp sgt i32 %M, 0
212 br i1 %cmp215, label %for.cond1.preheader.us.preheader, label %for.cond1.preheader.preheader
214 for.cond1.preheader.preheader:
215 br label %for.cond1.preheader
217 for.cond1.preheader.us.preheader:
218 br label %for.cond1.preheader.us
220 for.cond1.preheader.us:
221 %i.018.us = phi i32 [ %inc6.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ]
222 %mul.us = mul nsw i32 %i.018.us, %M
223 br label %for.body4.us
226 %j.016.us = phi i32 [ 0, %for.cond1.preheader.us ], [ %inc.us, %for.body4.us ]
227 %add.us = add nsw i32 %j.016.us, %mul.us
228 %idxprom.us = sext i32 %add.us to i64
229 %arrayidx.us = getelementptr inbounds i32, ptr %A, i64 %idxprom.us
230 %0 = load i32, ptr %arrayidx.us, align 4
231 tail call void @g(i32 %0)
232 %inc.us = add nuw nsw i32 %j.016.us, 1
233 %cmp2.us = icmp slt i32 %inc.us, %M
234 br i1 %cmp2.us, label %for.body4.us, label %for.cond1.for.cond.cleanup3_crit_edge.us
236 for.cond1.for.cond.cleanup3_crit_edge.us:
237 %inc6.us = add nuw nsw i32 %i.018.us, 1
238 %cmp.us = icmp slt i32 %inc6.us, %N
239 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.cond.cleanup.loopexit
242 %i.018 = phi i32 [ %inc6, %for.cond1.preheader ], [ 0, %for.cond1.preheader.preheader ]
243 %inc6 = add nuw nsw i32 %i.018, 1
244 %cmp = icmp slt i32 %inc6, %N
245 br i1 %cmp, label %for.cond1.preheader, label %for.cond.cleanup.loopexit19
247 for.cond.cleanup.loopexit:
248 br label %for.cond.cleanup
250 for.cond.cleanup.loopexit19:
251 br label %for.cond.cleanup
257 ; This test case corresponds to this input:
259 ; void foo2_zext(unsigned *A, ..) {
260 ; for (unsigned i = 0; i < N; ++i)
261 ; for (unsigned j = 0; j < M; ++j)
264 define void @foo2_zext(i32* nocapture readonly %A, i32 %N, i32 %M) {
265 ; CHECK-LABEL: @foo2_zext(
267 ; CHECK-NEXT: [[CMP17_NOT:%.*]] = icmp eq i32 [[N:%.*]], 0
268 ; CHECK-NEXT: br i1 [[CMP17_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]]
269 ; CHECK: for.cond1.preheader.lr.ph:
270 ; CHECK-NEXT: [[CMP215_NOT:%.*]] = icmp eq i32 [[M:%.*]], 0
271 ; CHECK-NEXT: br i1 [[CMP215_NOT]], label [[FOR_COND1_PREHEADER_PREHEADER:%.*]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]]
272 ; CHECK: for.cond1.preheader.us.preheader:
273 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[M]] to i64
274 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[N]] to i64
275 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 [[TMP0]], [[TMP1]]
276 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
277 ; CHECK: for.cond1.preheader.preheader:
278 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER:%.*]]
279 ; CHECK: for.cond1.preheader.us:
280 ; CHECK-NEXT: [[INDVAR1:%.*]] = phi i64 [ [[INDVAR_NEXT2:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
281 ; CHECK-NEXT: [[FLATTEN_TRUNCIV:%.*]] = trunc i64 [[INDVAR1]] to i32
282 ; CHECK-NEXT: br label [[FOR_BODY4_US:%.*]]
283 ; CHECK: for.body4.us:
284 ; CHECK-NEXT: [[IDXPROM_US:%.*]] = zext i32 [[FLATTEN_TRUNCIV]] to i64
285 ; CHECK-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[IDXPROM_US]]
286 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX_US]], align 4
287 ; CHECK-NEXT: tail call void @g(i32 [[TMP2]])
288 ; CHECK-NEXT: br label [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US]]
289 ; CHECK: for.cond1.for.cond.cleanup3_crit_edge.us:
290 ; CHECK-NEXT: [[INDVAR_NEXT2]] = add i64 [[INDVAR1]], 1
291 ; CHECK-NEXT: [[CMP_US:%.*]] = icmp ult i64 [[INDVAR_NEXT2]], [[FLATTEN_TRIPCOUNT]]
292 ; CHECK-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT19:%.*]]
293 ; CHECK: for.cond1.preheader:
294 ; CHECK-NEXT: [[I_018:%.*]] = phi i32 [ [[INC6:%.*]], [[FOR_COND1_PREHEADER]] ], [ 0, [[FOR_COND1_PREHEADER_PREHEADER]] ]
295 ; CHECK-NEXT: [[INC6]] = add i32 [[I_018]], 1
296 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[INC6]], [[N]]
297 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_COND1_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
298 ; CHECK: for.cond.cleanup.loopexit:
299 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
300 ; CHECK: for.cond.cleanup.loopexit19:
301 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
302 ; CHECK: for.cond.cleanup:
303 ; CHECK-NEXT: ret void
305 ; DONTWIDEN-LABEL: @foo2_zext(
306 ; DONTWIDEN-NEXT: entry:
307 ; DONTWIDEN-NEXT: [[CMP17_NOT:%.*]] = icmp eq i32 [[N:%.*]], 0
308 ; DONTWIDEN-NEXT: br i1 [[CMP17_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]]
309 ; DONTWIDEN: for.cond1.preheader.lr.ph:
310 ; DONTWIDEN-NEXT: [[CMP215_NOT:%.*]] = icmp eq i32 [[M:%.*]], 0
311 ; DONTWIDEN-NEXT: br i1 [[CMP215_NOT]], label [[FOR_COND1_PREHEADER_PREHEADER:%.*]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]]
312 ; DONTWIDEN: for.cond1.preheader.us.preheader:
313 ; DONTWIDEN-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
314 ; DONTWIDEN: for.cond1.preheader.preheader:
315 ; DONTWIDEN-NEXT: br label [[FOR_COND1_PREHEADER:%.*]]
316 ; DONTWIDEN: for.cond1.preheader.us:
317 ; DONTWIDEN-NEXT: [[I_018_US:%.*]] = phi i32 [ [[INC6_US:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
318 ; DONTWIDEN-NEXT: [[MUL_US:%.*]] = mul i32 [[I_018_US]], [[M]]
319 ; DONTWIDEN-NEXT: br label [[FOR_BODY4_US:%.*]]
320 ; DONTWIDEN: for.body4.us:
321 ; DONTWIDEN-NEXT: [[J_016_US:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_US]] ], [ [[INC_US:%.*]], [[FOR_BODY4_US]] ]
322 ; DONTWIDEN-NEXT: [[ADD_US:%.*]] = add i32 [[J_016_US]], [[MUL_US]]
323 ; DONTWIDEN-NEXT: [[IDXPROM_US:%.*]] = zext i32 [[ADD_US]] to i64
324 ; DONTWIDEN-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[IDXPROM_US]]
325 ; DONTWIDEN-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX_US]], align 4
326 ; DONTWIDEN-NEXT: tail call void @g(i32 [[TMP0]])
327 ; DONTWIDEN-NEXT: [[INC_US]] = add nuw i32 [[J_016_US]], 1
328 ; DONTWIDEN-NEXT: [[CMP2_US:%.*]] = icmp ult i32 [[INC_US]], [[M]]
329 ; DONTWIDEN-NEXT: br i1 [[CMP2_US]], label [[FOR_BODY4_US]], label [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US]]
330 ; DONTWIDEN: for.cond1.for.cond.cleanup3_crit_edge.us:
331 ; DONTWIDEN-NEXT: [[INC6_US]] = add i32 [[I_018_US]], 1
332 ; DONTWIDEN-NEXT: [[CMP_US:%.*]] = icmp ult i32 [[INC6_US]], [[N]]
333 ; DONTWIDEN-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT19:%.*]]
334 ; DONTWIDEN: for.cond1.preheader:
335 ; DONTWIDEN-NEXT: [[I_018:%.*]] = phi i32 [ [[INC6:%.*]], [[FOR_COND1_PREHEADER]] ], [ 0, [[FOR_COND1_PREHEADER_PREHEADER]] ]
336 ; DONTWIDEN-NEXT: [[INC6]] = add i32 [[I_018]], 1
337 ; DONTWIDEN-NEXT: [[CMP:%.*]] = icmp ult i32 [[INC6]], [[N]]
338 ; DONTWIDEN-NEXT: br i1 [[CMP]], label [[FOR_COND1_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
339 ; DONTWIDEN: for.cond.cleanup.loopexit:
340 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
341 ; DONTWIDEN: for.cond.cleanup.loopexit19:
342 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
343 ; DONTWIDEN: for.cond.cleanup:
344 ; DONTWIDEN-NEXT: ret void
347 %cmp17.not = icmp eq i32 %N, 0
348 br i1 %cmp17.not, label %for.cond.cleanup, label %for.cond1.preheader.lr.ph
350 for.cond1.preheader.lr.ph:
351 %cmp215.not = icmp eq i32 %M, 0
352 br i1 %cmp215.not, label %for.cond1.preheader.preheader, label %for.cond1.preheader.us.preheader
354 for.cond1.preheader.us.preheader:
355 br label %for.cond1.preheader.us
357 for.cond1.preheader.preheader:
358 br label %for.cond1.preheader
360 for.cond1.preheader.us:
361 %i.018.us = phi i32 [ %inc6.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ]
362 %mul.us = mul i32 %i.018.us, %M
363 br label %for.body4.us
366 %j.016.us = phi i32 [ 0, %for.cond1.preheader.us ], [ %inc.us, %for.body4.us ]
367 %add.us = add i32 %j.016.us, %mul.us
368 %idxprom.us = zext i32 %add.us to i64
369 %arrayidx.us = getelementptr inbounds i32, ptr %A, i64 %idxprom.us
370 %0 = load i32, ptr %arrayidx.us, align 4
371 tail call void @g(i32 %0)
372 %inc.us = add nuw i32 %j.016.us, 1
373 %cmp2.us = icmp ult i32 %inc.us, %M
374 br i1 %cmp2.us, label %for.body4.us, label %for.cond1.for.cond.cleanup3_crit_edge.us
376 for.cond1.for.cond.cleanup3_crit_edge.us:
377 %inc6.us = add i32 %i.018.us, 1
378 %cmp.us = icmp ult i32 %inc6.us, %N
379 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.cond.cleanup.loopexit19
382 %i.018 = phi i32 [ %inc6, %for.cond1.preheader ], [ 0, %for.cond1.preheader.preheader ]
383 %inc6 = add i32 %i.018, 1
384 %cmp = icmp ult i32 %inc6, %N
385 br i1 %cmp, label %for.cond1.preheader, label %for.cond.cleanup.loopexit
387 for.cond.cleanup.loopexit:
388 br label %for.cond.cleanup
390 for.cond.cleanup.loopexit19:
391 br label %for.cond.cleanup
397 define void @zext(i32 %N, ptr nocapture %A, i16 %val) {
398 ; CHECK-LABEL: @zext(
400 ; CHECK-NEXT: [[CMP20_NOT:%.*]] = icmp eq i32 [[N:%.*]], 0
401 ; CHECK-NEXT: br i1 [[CMP20_NOT]], label [[FOR_END9:%.*]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]]
402 ; CHECK: for.cond1.preheader.us.preheader:
403 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[N]] to i64
404 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[N]] to i64
405 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 [[TMP0]], [[TMP1]]
406 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
407 ; CHECK: for.cond1.preheader.us:
408 ; CHECK-NEXT: [[INDVAR1:%.*]] = phi i64 [ [[INDVAR_NEXT2:%.*]], [[FOR_COND1_FOR_INC7_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
409 ; CHECK-NEXT: [[FLATTEN_TRUNCIV:%.*]] = trunc i64 [[INDVAR1]] to i32
410 ; CHECK-NEXT: br label [[FOR_BODY3_US:%.*]]
411 ; CHECK: for.body3.us:
412 ; CHECK-NEXT: [[IDXPROM_US:%.*]] = zext i32 [[FLATTEN_TRUNCIV]] to i64
413 ; CHECK-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i16, ptr [[A:%.*]], i64 [[IDXPROM_US]]
414 ; CHECK-NEXT: [[TMP2:%.*]] = load i16, ptr [[ARRAYIDX_US]], align 2
415 ; CHECK-NEXT: [[ADD5_US:%.*]] = add i16 [[TMP2]], [[VAL:%.*]]
416 ; CHECK-NEXT: store i16 [[ADD5_US]], ptr [[ARRAYIDX_US]], align 2
417 ; CHECK-NEXT: br label [[FOR_COND1_FOR_INC7_CRIT_EDGE_US]]
418 ; CHECK: for.cond1.for.inc7_crit_edge.us:
419 ; CHECK-NEXT: [[INDVAR_NEXT2]] = add i64 [[INDVAR1]], 1
420 ; CHECK-NEXT: [[CMP_US:%.*]] = icmp ult i64 [[INDVAR_NEXT2]], [[FLATTEN_TRIPCOUNT]]
421 ; CHECK-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_END9_LOOPEXIT:%.*]]
422 ; CHECK: for.end9.loopexit:
423 ; CHECK-NEXT: br label [[FOR_END9]]
425 ; CHECK-NEXT: ret void
427 ; DONTWIDEN-LABEL: @zext(
428 ; DONTWIDEN-NEXT: entry:
429 ; DONTWIDEN-NEXT: [[CMP20_NOT:%.*]] = icmp eq i32 [[N:%.*]], 0
430 ; DONTWIDEN-NEXT: br i1 [[CMP20_NOT]], label [[FOR_END9:%.*]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]]
431 ; DONTWIDEN: for.cond1.preheader.us.preheader:
432 ; DONTWIDEN-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
433 ; DONTWIDEN: for.cond1.preheader.us:
434 ; DONTWIDEN-NEXT: [[I_021_US:%.*]] = phi i32 [ [[INC8_US:%.*]], [[FOR_COND1_FOR_INC7_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
435 ; DONTWIDEN-NEXT: [[MUL_US:%.*]] = mul i32 [[I_021_US]], [[N]]
436 ; DONTWIDEN-NEXT: br label [[FOR_BODY3_US:%.*]]
437 ; DONTWIDEN: for.body3.us:
438 ; DONTWIDEN-NEXT: [[J_019_US:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_US]] ], [ [[INC_US:%.*]], [[FOR_BODY3_US]] ]
439 ; DONTWIDEN-NEXT: [[ADD_US:%.*]] = add i32 [[J_019_US]], [[MUL_US]]
440 ; DONTWIDEN-NEXT: [[IDXPROM_US:%.*]] = zext i32 [[ADD_US]] to i64
441 ; DONTWIDEN-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i16, ptr [[A:%.*]], i64 [[IDXPROM_US]]
442 ; DONTWIDEN-NEXT: [[TMP0:%.*]] = load i16, ptr [[ARRAYIDX_US]], align 2
443 ; DONTWIDEN-NEXT: [[ADD5_US:%.*]] = add i16 [[TMP0]], [[VAL:%.*]]
444 ; DONTWIDEN-NEXT: store i16 [[ADD5_US]], ptr [[ARRAYIDX_US]], align 2
445 ; DONTWIDEN-NEXT: [[INC_US]] = add nuw i32 [[J_019_US]], 1
446 ; DONTWIDEN-NEXT: [[CMP2_US:%.*]] = icmp ult i32 [[INC_US]], [[N]]
447 ; DONTWIDEN-NEXT: br i1 [[CMP2_US]], label [[FOR_BODY3_US]], label [[FOR_COND1_FOR_INC7_CRIT_EDGE_US]]
448 ; DONTWIDEN: for.cond1.for.inc7_crit_edge.us:
449 ; DONTWIDEN-NEXT: [[INC8_US]] = add i32 [[I_021_US]], 1
450 ; DONTWIDEN-NEXT: [[CMP_US:%.*]] = icmp ult i32 [[INC8_US]], [[N]]
451 ; DONTWIDEN-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_END9_LOOPEXIT:%.*]]
452 ; DONTWIDEN: for.end9.loopexit:
453 ; DONTWIDEN-NEXT: br label [[FOR_END9]]
454 ; DONTWIDEN: for.end9:
455 ; DONTWIDEN-NEXT: ret void
458 %cmp20.not = icmp eq i32 %N, 0
459 br i1 %cmp20.not, label %for.end9, label %for.cond1.preheader.us.preheader
461 for.cond1.preheader.us.preheader:
462 br label %for.cond1.preheader.us
464 for.cond1.preheader.us:
465 %i.021.us = phi i32 [ %inc8.us, %for.cond1.for.inc7_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ]
466 %mul.us = mul i32 %i.021.us, %N
467 br label %for.body3.us
470 %j.019.us = phi i32 [ 0, %for.cond1.preheader.us ], [ %inc.us, %for.body3.us ]
471 %add.us = add i32 %j.019.us, %mul.us
472 %idxprom.us = zext i32 %add.us to i64
473 %arrayidx.us = getelementptr inbounds i16, ptr %A, i64 %idxprom.us
474 %0 = load i16, ptr %arrayidx.us, align 2
475 %add5.us = add i16 %0, %val
476 store i16 %add5.us, ptr %arrayidx.us, align 2
477 %inc.us = add nuw i32 %j.019.us, 1
478 %cmp2.us = icmp ult i32 %inc.us, %N
479 br i1 %cmp2.us, label %for.body3.us, label %for.cond1.for.inc7_crit_edge.us
481 for.cond1.for.inc7_crit_edge.us:
482 %inc8.us = add i32 %i.021.us, 1
483 %cmp.us = icmp ult i32 %inc8.us, %N
484 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.end9.loopexit
493 ; This IR corresponds to this input:
495 ; void test(char n, char m) {
496 ; for(char i = 0; i < n; i++)
497 ; for(char j = 0; j < m; j++) {
503 define void @test(i8 %n, i8 %m) {
504 ; CHECK-LABEL: @test(
506 ; CHECK-NEXT: [[CMP25_NOT:%.*]] = icmp eq i8 [[N:%.*]], 0
507 ; CHECK-NEXT: br i1 [[CMP25_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_COND3_PREHEADER_LR_PH:%.*]]
508 ; CHECK: for.cond3.preheader.lr.ph:
509 ; CHECK-NEXT: [[CMP623_NOT:%.*]] = icmp eq i8 [[M:%.*]], 0
510 ; CHECK-NEXT: br i1 [[CMP623_NOT]], label [[FOR_COND3_PREHEADER_PREHEADER:%.*]], label [[FOR_COND3_PREHEADER_US_PREHEADER:%.*]]
511 ; CHECK: for.cond3.preheader.preheader:
512 ; CHECK-NEXT: br label [[FOR_COND3_PREHEADER:%.*]]
513 ; CHECK: for.cond3.preheader.us.preheader:
514 ; CHECK-NEXT: [[TMP0:%.*]] = zext i8 [[M]] to i64
515 ; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[N]] to i64
516 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 [[TMP0]], [[TMP1]]
517 ; CHECK-NEXT: br label [[FOR_COND3_PREHEADER_US:%.*]]
518 ; CHECK: for.cond3.preheader.us:
519 ; CHECK-NEXT: [[INDVAR2:%.*]] = phi i64 [ [[INDVAR_NEXT3:%.*]], [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND3_PREHEADER_US_PREHEADER]] ]
520 ; CHECK-NEXT: [[FLATTEN_TRUNCIV:%.*]] = trunc i64 [[INDVAR2]] to i8
521 ; CHECK-NEXT: br label [[FOR_BODY9_US:%.*]]
522 ; CHECK: for.body9.us:
523 ; CHECK-NEXT: [[CONV14_US:%.*]] = zext i8 [[FLATTEN_TRUNCIV]] to i32
524 ; CHECK-NEXT: [[CALL_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
525 ; CHECK-NEXT: br label [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US]]
526 ; CHECK: for.cond3.for.cond.cleanup8_crit_edge.us:
527 ; CHECK-NEXT: [[INDVAR_NEXT3]] = add i64 [[INDVAR2]], 1
528 ; CHECK-NEXT: [[CMP_US:%.*]] = icmp ult i64 [[INDVAR_NEXT3]], [[FLATTEN_TRIPCOUNT]]
529 ; CHECK-NEXT: br i1 [[CMP_US]], label [[FOR_COND3_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT1:%.*]]
530 ; CHECK: for.cond3.preheader:
531 ; CHECK-NEXT: [[I_026:%.*]] = phi i8 [ [[INC16:%.*]], [[FOR_COND3_PREHEADER]] ], [ 0, [[FOR_COND3_PREHEADER_PREHEADER]] ]
532 ; CHECK-NEXT: [[INC16]] = add i8 [[I_026]], 1
533 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[INC16]], [[N]]
534 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_COND3_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
535 ; CHECK: for.cond.cleanup.loopexit:
536 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
537 ; CHECK: for.cond.cleanup.loopexit1:
538 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
539 ; CHECK: for.cond.cleanup:
540 ; CHECK-NEXT: ret void
542 ; DONTWIDEN-LABEL: @test(
543 ; DONTWIDEN-NEXT: entry:
544 ; DONTWIDEN-NEXT: [[CMP25_NOT:%.*]] = icmp eq i8 [[N:%.*]], 0
545 ; DONTWIDEN-NEXT: br i1 [[CMP25_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_COND3_PREHEADER_LR_PH:%.*]]
546 ; DONTWIDEN: for.cond3.preheader.lr.ph:
547 ; DONTWIDEN-NEXT: [[CMP623_NOT:%.*]] = icmp eq i8 [[M:%.*]], 0
548 ; DONTWIDEN-NEXT: br i1 [[CMP623_NOT]], label [[FOR_COND3_PREHEADER_PREHEADER:%.*]], label [[FOR_COND3_PREHEADER_US_PREHEADER:%.*]]
549 ; DONTWIDEN: for.cond3.preheader.preheader:
550 ; DONTWIDEN-NEXT: br label [[FOR_COND3_PREHEADER:%.*]]
551 ; DONTWIDEN: for.cond3.preheader.us.preheader:
552 ; DONTWIDEN-NEXT: br label [[FOR_COND3_PREHEADER_US:%.*]]
553 ; DONTWIDEN: for.cond3.preheader.us:
554 ; DONTWIDEN-NEXT: [[I_026_US:%.*]] = phi i8 [ [[INC16_US:%.*]], [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND3_PREHEADER_US_PREHEADER]] ]
555 ; DONTWIDEN-NEXT: [[MUL_US:%.*]] = mul i8 [[I_026_US]], [[M]]
556 ; DONTWIDEN-NEXT: br label [[FOR_BODY9_US:%.*]]
557 ; DONTWIDEN: for.body9.us:
558 ; DONTWIDEN-NEXT: [[J_024_US:%.*]] = phi i8 [ 0, [[FOR_COND3_PREHEADER_US]] ], [ [[INC_US:%.*]], [[FOR_BODY9_US]] ]
559 ; DONTWIDEN-NEXT: [[ADD_US:%.*]] = add i8 [[J_024_US]], [[MUL_US]]
560 ; DONTWIDEN-NEXT: [[CONV14_US:%.*]] = zext i8 [[ADD_US]] to i32
561 ; DONTWIDEN-NEXT: [[CALL_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
562 ; DONTWIDEN-NEXT: [[INC_US]] = add nuw i8 [[J_024_US]], 1
563 ; DONTWIDEN-NEXT: [[CMP6_US:%.*]] = icmp ult i8 [[INC_US]], [[M]]
564 ; DONTWIDEN-NEXT: br i1 [[CMP6_US]], label [[FOR_BODY9_US]], label [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US]]
565 ; DONTWIDEN: for.cond3.for.cond.cleanup8_crit_edge.us:
566 ; DONTWIDEN-NEXT: [[INC16_US]] = add i8 [[I_026_US]], 1
567 ; DONTWIDEN-NEXT: [[CMP_US:%.*]] = icmp ult i8 [[INC16_US]], [[N]]
568 ; DONTWIDEN-NEXT: br i1 [[CMP_US]], label [[FOR_COND3_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT1:%.*]]
569 ; DONTWIDEN: for.cond3.preheader:
570 ; DONTWIDEN-NEXT: [[I_026:%.*]] = phi i8 [ [[INC16:%.*]], [[FOR_COND3_PREHEADER]] ], [ 0, [[FOR_COND3_PREHEADER_PREHEADER]] ]
571 ; DONTWIDEN-NEXT: [[INC16]] = add i8 [[I_026]], 1
572 ; DONTWIDEN-NEXT: [[CMP:%.*]] = icmp ult i8 [[INC16]], [[N]]
573 ; DONTWIDEN-NEXT: br i1 [[CMP]], label [[FOR_COND3_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
574 ; DONTWIDEN: for.cond.cleanup.loopexit:
575 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
576 ; DONTWIDEN: for.cond.cleanup.loopexit1:
577 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
578 ; DONTWIDEN: for.cond.cleanup:
579 ; DONTWIDEN-NEXT: ret void
582 %cmp25.not = icmp eq i8 %n, 0
583 br i1 %cmp25.not, label %for.cond.cleanup, label %for.cond3.preheader.lr.ph
585 for.cond3.preheader.lr.ph:
586 %cmp623.not = icmp eq i8 %m, 0
587 br i1 %cmp623.not, label %for.cond3.preheader.preheader, label %for.cond3.preheader.us.preheader
589 for.cond3.preheader.preheader:
590 br label %for.cond3.preheader
592 for.cond3.preheader.us.preheader:
593 br label %for.cond3.preheader.us
595 for.cond3.preheader.us:
596 %i.026.us = phi i8 [ %inc16.us, %for.cond3.for.cond.cleanup8_crit_edge.us ], [ 0, %for.cond3.preheader.us.preheader ]
597 %mul.us = mul i8 %i.026.us, %m
598 br label %for.body9.us
601 %j.024.us = phi i8 [ 0, %for.cond3.preheader.us ], [ %inc.us, %for.body9.us ]
602 %add.us = add i8 %j.024.us, %mul.us
603 %conv14.us = zext i8 %add.us to i32
604 %call.us = tail call i32 @use_32(i32 %conv14.us) #2
605 %inc.us = add nuw i8 %j.024.us, 1
606 %cmp6.us = icmp ult i8 %inc.us, %m
607 br i1 %cmp6.us, label %for.body9.us, label %for.cond3.for.cond.cleanup8_crit_edge.us
609 for.cond3.for.cond.cleanup8_crit_edge.us:
610 %inc16.us = add i8 %i.026.us, 1
611 %cmp.us = icmp ult i8 %inc16.us, %n
612 br i1 %cmp.us, label %for.cond3.preheader.us, label %for.cond.cleanup
615 %i.026 = phi i8 [ %inc16, %for.cond3.preheader ], [ 0, %for.cond3.preheader.preheader ]
616 %inc16 = add i8 %i.026, 1
617 %cmp = icmp ult i8 %inc16, %n
618 br i1 %cmp, label %for.cond3.preheader, label %for.cond.cleanup
624 ; This IR corresponds to this input:
626 ; void test3(char n, char m) {
627 ; for(char i = 0; i < n; i++)
628 ; for(char j = 0; j < m; j++) {
638 define void @test3(i8 %n, i8 %m) {
639 ; CHECK-LABEL: @test3(
641 ; CHECK-NEXT: [[CMP37_NOT:%.*]] = icmp eq i8 [[N:%.*]], 0
642 ; CHECK-NEXT: br i1 [[CMP37_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_COND3_PREHEADER_LR_PH:%.*]]
643 ; CHECK: for.cond3.preheader.lr.ph:
644 ; CHECK-NEXT: [[CMP635_NOT:%.*]] = icmp eq i8 [[M:%.*]], 0
645 ; CHECK-NEXT: br i1 [[CMP635_NOT]], label [[FOR_COND3_PREHEADER_PREHEADER:%.*]], label [[FOR_COND3_PREHEADER_US_PREHEADER:%.*]]
646 ; CHECK: for.cond3.preheader.preheader:
647 ; CHECK-NEXT: br label [[FOR_COND3_PREHEADER:%.*]]
648 ; CHECK: for.cond3.preheader.us.preheader:
649 ; CHECK-NEXT: [[TMP0:%.*]] = zext i8 [[M]] to i64
650 ; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[N]] to i64
651 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 [[TMP0]], [[TMP1]]
652 ; CHECK-NEXT: br label [[FOR_COND3_PREHEADER_US:%.*]]
653 ; CHECK: for.cond3.preheader.us:
654 ; CHECK-NEXT: [[INDVAR2:%.*]] = phi i64 [ [[INDVAR_NEXT3:%.*]], [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND3_PREHEADER_US_PREHEADER]] ]
655 ; CHECK-NEXT: [[FLATTEN_TRUNCIV:%.*]] = trunc i64 [[INDVAR2]] to i8
656 ; CHECK-NEXT: br label [[FOR_BODY9_US:%.*]]
657 ; CHECK: for.body9.us:
658 ; CHECK-NEXT: [[CONV14_US:%.*]] = zext i8 [[FLATTEN_TRUNCIV]] to i32
659 ; CHECK-NEXT: [[CALL_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
660 ; CHECK-NEXT: [[CONV15_US:%.*]] = zext i8 [[FLATTEN_TRUNCIV]] to i16
661 ; CHECK-NEXT: [[CALL16_US:%.*]] = tail call i32 @use_16(i16 [[CONV15_US]])
662 ; CHECK-NEXT: [[CALL18_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
663 ; CHECK-NEXT: [[CALL20_US:%.*]] = tail call i32 @use_16(i16 [[CONV15_US]])
664 ; CHECK-NEXT: [[CONV21_US:%.*]] = zext i8 [[FLATTEN_TRUNCIV]] to i64
665 ; CHECK-NEXT: [[CALL22_US:%.*]] = tail call i32 @use_64(i64 [[CONV21_US]])
666 ; CHECK-NEXT: br label [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US]]
667 ; CHECK: for.cond3.for.cond.cleanup8_crit_edge.us:
668 ; CHECK-NEXT: [[INDVAR_NEXT3]] = add i64 [[INDVAR2]], 1
669 ; CHECK-NEXT: [[CMP_US:%.*]] = icmp ult i64 [[INDVAR_NEXT3]], [[FLATTEN_TRIPCOUNT]]
670 ; CHECK-NEXT: br i1 [[CMP_US]], label [[FOR_COND3_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT1:%.*]]
671 ; CHECK: for.cond3.preheader:
672 ; CHECK-NEXT: [[I_038:%.*]] = phi i8 [ [[INC24:%.*]], [[FOR_COND3_PREHEADER]] ], [ 0, [[FOR_COND3_PREHEADER_PREHEADER]] ]
673 ; CHECK-NEXT: [[INC24]] = add i8 [[I_038]], 1
674 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[INC24]], [[N]]
675 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_COND3_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
676 ; CHECK: for.cond.cleanup.loopexit:
677 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
678 ; CHECK: for.cond.cleanup.loopexit1:
679 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
680 ; CHECK: for.cond.cleanup:
681 ; CHECK-NEXT: ret void
683 ; DONTWIDEN-LABEL: @test3(
684 ; DONTWIDEN-NEXT: entry:
685 ; DONTWIDEN-NEXT: [[CMP37_NOT:%.*]] = icmp eq i8 [[N:%.*]], 0
686 ; DONTWIDEN-NEXT: br i1 [[CMP37_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_COND3_PREHEADER_LR_PH:%.*]]
687 ; DONTWIDEN: for.cond3.preheader.lr.ph:
688 ; DONTWIDEN-NEXT: [[CMP635_NOT:%.*]] = icmp eq i8 [[M:%.*]], 0
689 ; DONTWIDEN-NEXT: br i1 [[CMP635_NOT]], label [[FOR_COND3_PREHEADER_PREHEADER:%.*]], label [[FOR_COND3_PREHEADER_US_PREHEADER:%.*]]
690 ; DONTWIDEN: for.cond3.preheader.preheader:
691 ; DONTWIDEN-NEXT: br label [[FOR_COND3_PREHEADER:%.*]]
692 ; DONTWIDEN: for.cond3.preheader.us.preheader:
693 ; DONTWIDEN-NEXT: br label [[FOR_COND3_PREHEADER_US:%.*]]
694 ; DONTWIDEN: for.cond3.preheader.us:
695 ; DONTWIDEN-NEXT: [[I_038_US:%.*]] = phi i8 [ [[INC24_US:%.*]], [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND3_PREHEADER_US_PREHEADER]] ]
696 ; DONTWIDEN-NEXT: [[MUL_US:%.*]] = mul i8 [[I_038_US]], [[M]]
697 ; DONTWIDEN-NEXT: br label [[FOR_BODY9_US:%.*]]
698 ; DONTWIDEN: for.body9.us:
699 ; DONTWIDEN-NEXT: [[J_036_US:%.*]] = phi i8 [ 0, [[FOR_COND3_PREHEADER_US]] ], [ [[INC_US:%.*]], [[FOR_BODY9_US]] ]
700 ; DONTWIDEN-NEXT: [[ADD_US:%.*]] = add i8 [[J_036_US]], [[MUL_US]]
701 ; DONTWIDEN-NEXT: [[CONV14_US:%.*]] = zext i8 [[ADD_US]] to i32
702 ; DONTWIDEN-NEXT: [[CALL_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
703 ; DONTWIDEN-NEXT: [[CONV15_US:%.*]] = zext i8 [[ADD_US]] to i16
704 ; DONTWIDEN-NEXT: [[CALL16_US:%.*]] = tail call i32 @use_16(i16 [[CONV15_US]])
705 ; DONTWIDEN-NEXT: [[CALL18_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
706 ; DONTWIDEN-NEXT: [[CALL20_US:%.*]] = tail call i32 @use_16(i16 [[CONV15_US]])
707 ; DONTWIDEN-NEXT: [[CONV21_US:%.*]] = zext i8 [[ADD_US]] to i64
708 ; DONTWIDEN-NEXT: [[CALL22_US:%.*]] = tail call i32 @use_64(i64 [[CONV21_US]])
709 ; DONTWIDEN-NEXT: [[INC_US]] = add nuw i8 [[J_036_US]], 1
710 ; DONTWIDEN-NEXT: [[CMP6_US:%.*]] = icmp ult i8 [[INC_US]], [[M]]
711 ; DONTWIDEN-NEXT: br i1 [[CMP6_US]], label [[FOR_BODY9_US]], label [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US]]
712 ; DONTWIDEN: for.cond3.for.cond.cleanup8_crit_edge.us:
713 ; DONTWIDEN-NEXT: [[INC24_US]] = add i8 [[I_038_US]], 1
714 ; DONTWIDEN-NEXT: [[CMP_US:%.*]] = icmp ult i8 [[INC24_US]], [[N]]
715 ; DONTWIDEN-NEXT: br i1 [[CMP_US]], label [[FOR_COND3_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT1:%.*]]
716 ; DONTWIDEN: for.cond3.preheader:
717 ; DONTWIDEN-NEXT: [[I_038:%.*]] = phi i8 [ [[INC24:%.*]], [[FOR_COND3_PREHEADER]] ], [ 0, [[FOR_COND3_PREHEADER_PREHEADER]] ]
718 ; DONTWIDEN-NEXT: [[INC24]] = add i8 [[I_038]], 1
719 ; DONTWIDEN-NEXT: [[CMP:%.*]] = icmp ult i8 [[INC24]], [[N]]
720 ; DONTWIDEN-NEXT: br i1 [[CMP]], label [[FOR_COND3_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
721 ; DONTWIDEN: for.cond.cleanup.loopexit:
722 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
723 ; DONTWIDEN: for.cond.cleanup.loopexit1:
724 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
725 ; DONTWIDEN: for.cond.cleanup:
726 ; DONTWIDEN-NEXT: ret void
729 %cmp37.not = icmp eq i8 %n, 0
730 br i1 %cmp37.not, label %for.cond.cleanup, label %for.cond3.preheader.lr.ph
732 for.cond3.preheader.lr.ph:
733 %cmp635.not = icmp eq i8 %m, 0
734 br i1 %cmp635.not, label %for.cond3.preheader.preheader, label %for.cond3.preheader.us.preheader
736 for.cond3.preheader.preheader:
737 br label %for.cond3.preheader
739 for.cond3.preheader.us.preheader:
740 br label %for.cond3.preheader.us
742 for.cond3.preheader.us:
743 %i.038.us = phi i8 [ %inc24.us, %for.cond3.for.cond.cleanup8_crit_edge.us ], [ 0, %for.cond3.preheader.us.preheader ]
744 %mul.us = mul i8 %i.038.us, %m
745 br label %for.body9.us
748 %j.036.us = phi i8 [ 0, %for.cond3.preheader.us ], [ %inc.us, %for.body9.us ]
749 %add.us = add i8 %j.036.us, %mul.us
750 %conv14.us = zext i8 %add.us to i32
751 %call.us = tail call i32 @use_32(i32 %conv14.us)
752 %conv15.us = zext i8 %add.us to i16
753 %call16.us = tail call i32 @use_16(i16 %conv15.us)
754 %call18.us = tail call i32 @use_32(i32 %conv14.us)
755 %call20.us = tail call i32 @use_16(i16 %conv15.us)
756 %conv21.us = zext i8 %add.us to i64
757 %call22.us = tail call i32 @use_64(i64 %conv21.us)
758 %inc.us = add nuw i8 %j.036.us, 1
759 %cmp6.us = icmp ult i8 %inc.us, %m
760 br i1 %cmp6.us, label %for.body9.us, label %for.cond3.for.cond.cleanup8_crit_edge.us
762 for.cond3.for.cond.cleanup8_crit_edge.us:
763 %inc24.us = add i8 %i.038.us, 1
764 %cmp.us = icmp ult i8 %inc24.us, %n
765 br i1 %cmp.us, label %for.cond3.preheader.us, label %for.cond.cleanup
768 %i.038 = phi i8 [ %inc24, %for.cond3.preheader ], [ 0, %for.cond3.preheader.preheader ]
769 %inc24 = add i8 %i.038, 1
770 %cmp = icmp ult i8 %inc24, %n
771 br i1 %cmp, label %for.cond3.preheader, label %for.cond.cleanup
777 ; This IR corresponds to this input:
779 ; void test4(short n, short m) {
780 ; for(short i = 0; i < n; i++)
781 ; for(short j = 0; j < m; j++) {
791 define void @test4(i16 %n, i16 %m) {
792 ; CHECK-LABEL: @test4(
794 ; CHECK-NEXT: [[CMP38:%.*]] = icmp sgt i16 [[N:%.*]], 0
795 ; CHECK-NEXT: br i1 [[CMP38]], label [[FOR_COND3_PREHEADER_LR_PH:%.*]], label [[FOR_COND_CLEANUP:%.*]]
796 ; CHECK: for.cond3.preheader.lr.ph:
797 ; CHECK-NEXT: [[CMP636:%.*]] = icmp sgt i16 [[M:%.*]], 0
798 ; CHECK-NEXT: br i1 [[CMP636]], label [[FOR_COND3_PREHEADER_US_PREHEADER:%.*]], label [[FOR_COND3_PREHEADER_PREHEADER:%.*]]
799 ; CHECK: for.cond3.preheader.preheader:
800 ; CHECK-NEXT: br label [[FOR_COND3_PREHEADER:%.*]]
801 ; CHECK: for.cond3.preheader.us.preheader:
802 ; CHECK-NEXT: [[TMP0:%.*]] = sext i16 [[M]] to i64
803 ; CHECK-NEXT: [[TMP1:%.*]] = sext i16 [[N]] to i64
804 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 [[TMP0]], [[TMP1]]
805 ; CHECK-NEXT: br label [[FOR_COND3_PREHEADER_US:%.*]]
806 ; CHECK: for.cond3.preheader.us:
807 ; CHECK-NEXT: [[INDVAR2:%.*]] = phi i64 [ [[INDVAR_NEXT3:%.*]], [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND3_PREHEADER_US_PREHEADER]] ]
808 ; CHECK-NEXT: [[FLATTEN_TRUNCIV:%.*]] = trunc i64 [[INDVAR2]] to i16
809 ; CHECK-NEXT: br label [[FOR_BODY9_US:%.*]]
810 ; CHECK: for.body9.us:
811 ; CHECK-NEXT: [[CONV14_US:%.*]] = sext i16 [[FLATTEN_TRUNCIV]] to i32
812 ; CHECK-NEXT: [[CALL_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
813 ; CHECK-NEXT: [[CALL15_US:%.*]] = tail call i32 @use_16(i16 [[FLATTEN_TRUNCIV]])
814 ; CHECK-NEXT: [[CALL17_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
815 ; CHECK-NEXT: [[CALL18_US:%.*]] = tail call i32 @use_16(i16 [[FLATTEN_TRUNCIV]])
816 ; CHECK-NEXT: [[CONV19_US:%.*]] = sext i16 [[FLATTEN_TRUNCIV]] to i64
817 ; CHECK-NEXT: [[CALL20_US:%.*]] = tail call i32 @use_64(i64 [[CONV19_US]])
818 ; CHECK-NEXT: br label [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US]]
819 ; CHECK: for.cond3.for.cond.cleanup8_crit_edge.us:
820 ; CHECK-NEXT: [[INDVAR_NEXT3]] = add i64 [[INDVAR2]], 1
821 ; CHECK-NEXT: [[CMP_US:%.*]] = icmp slt i64 [[INDVAR_NEXT3]], [[FLATTEN_TRIPCOUNT]]
822 ; CHECK-NEXT: br i1 [[CMP_US]], label [[FOR_COND3_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
823 ; CHECK: for.cond3.preheader:
824 ; CHECK-NEXT: [[I_039:%.*]] = phi i16 [ [[INC22:%.*]], [[FOR_COND3_PREHEADER]] ], [ 0, [[FOR_COND3_PREHEADER_PREHEADER]] ]
825 ; CHECK-NEXT: [[INC22]] = add i16 [[I_039]], 1
826 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[INC22]], [[N]]
827 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_COND3_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT1:%.*]]
828 ; CHECK: for.cond.cleanup.loopexit:
829 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
830 ; CHECK: for.cond.cleanup.loopexit1:
831 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
832 ; CHECK: for.cond.cleanup:
833 ; CHECK-NEXT: ret void
835 ; DONTWIDEN-LABEL: @test4(
836 ; DONTWIDEN-NEXT: entry:
837 ; DONTWIDEN-NEXT: [[CMP38:%.*]] = icmp sgt i16 [[N:%.*]], 0
838 ; DONTWIDEN-NEXT: br i1 [[CMP38]], label [[FOR_COND3_PREHEADER_LR_PH:%.*]], label [[FOR_COND_CLEANUP:%.*]]
839 ; DONTWIDEN: for.cond3.preheader.lr.ph:
840 ; DONTWIDEN-NEXT: [[CMP636:%.*]] = icmp sgt i16 [[M:%.*]], 0
841 ; DONTWIDEN-NEXT: br i1 [[CMP636]], label [[FOR_COND3_PREHEADER_US_PREHEADER:%.*]], label [[FOR_COND3_PREHEADER_PREHEADER:%.*]]
842 ; DONTWIDEN: for.cond3.preheader.preheader:
843 ; DONTWIDEN-NEXT: br label [[FOR_COND3_PREHEADER:%.*]]
844 ; DONTWIDEN: for.cond3.preheader.us.preheader:
845 ; DONTWIDEN-NEXT: br label [[FOR_COND3_PREHEADER_US:%.*]]
846 ; DONTWIDEN: for.cond3.preheader.us:
847 ; DONTWIDEN-NEXT: [[I_039_US:%.*]] = phi i16 [ [[INC22_US:%.*]], [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND3_PREHEADER_US_PREHEADER]] ]
848 ; DONTWIDEN-NEXT: [[MUL_US:%.*]] = mul i16 [[I_039_US]], [[M]]
849 ; DONTWIDEN-NEXT: br label [[FOR_BODY9_US:%.*]]
850 ; DONTWIDEN: for.body9.us:
851 ; DONTWIDEN-NEXT: [[J_037_US:%.*]] = phi i16 [ 0, [[FOR_COND3_PREHEADER_US]] ], [ [[INC_US:%.*]], [[FOR_BODY9_US]] ]
852 ; DONTWIDEN-NEXT: [[ADD_US:%.*]] = add i16 [[J_037_US]], [[MUL_US]]
853 ; DONTWIDEN-NEXT: [[CONV14_US:%.*]] = sext i16 [[ADD_US]] to i32
854 ; DONTWIDEN-NEXT: [[CALL_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
855 ; DONTWIDEN-NEXT: [[CALL15_US:%.*]] = tail call i32 @use_16(i16 [[ADD_US]])
856 ; DONTWIDEN-NEXT: [[CALL17_US:%.*]] = tail call i32 @use_32(i32 [[CONV14_US]])
857 ; DONTWIDEN-NEXT: [[CALL18_US:%.*]] = tail call i32 @use_16(i16 [[ADD_US]])
858 ; DONTWIDEN-NEXT: [[CONV19_US:%.*]] = sext i16 [[ADD_US]] to i64
859 ; DONTWIDEN-NEXT: [[CALL20_US:%.*]] = tail call i32 @use_64(i64 [[CONV19_US]])
860 ; DONTWIDEN-NEXT: [[INC_US]] = add nuw nsw i16 [[J_037_US]], 1
861 ; DONTWIDEN-NEXT: [[CMP6_US:%.*]] = icmp slt i16 [[INC_US]], [[M]]
862 ; DONTWIDEN-NEXT: br i1 [[CMP6_US]], label [[FOR_BODY9_US]], label [[FOR_COND3_FOR_COND_CLEANUP8_CRIT_EDGE_US]]
863 ; DONTWIDEN: for.cond3.for.cond.cleanup8_crit_edge.us:
864 ; DONTWIDEN-NEXT: [[INC22_US]] = add i16 [[I_039_US]], 1
865 ; DONTWIDEN-NEXT: [[CMP_US:%.*]] = icmp slt i16 [[INC22_US]], [[N]]
866 ; DONTWIDEN-NEXT: br i1 [[CMP_US]], label [[FOR_COND3_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
867 ; DONTWIDEN: for.cond3.preheader:
868 ; DONTWIDEN-NEXT: [[I_039:%.*]] = phi i16 [ [[INC22:%.*]], [[FOR_COND3_PREHEADER]] ], [ 0, [[FOR_COND3_PREHEADER_PREHEADER]] ]
869 ; DONTWIDEN-NEXT: [[INC22]] = add i16 [[I_039]], 1
870 ; DONTWIDEN-NEXT: [[CMP:%.*]] = icmp slt i16 [[INC22]], [[N]]
871 ; DONTWIDEN-NEXT: br i1 [[CMP]], label [[FOR_COND3_PREHEADER]], label [[FOR_COND_CLEANUP_LOOPEXIT1:%.*]]
872 ; DONTWIDEN: for.cond.cleanup.loopexit:
873 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
874 ; DONTWIDEN: for.cond.cleanup.loopexit1:
875 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
876 ; DONTWIDEN: for.cond.cleanup:
877 ; DONTWIDEN-NEXT: ret void
880 %cmp38 = icmp sgt i16 %n, 0
881 br i1 %cmp38, label %for.cond3.preheader.lr.ph, label %for.cond.cleanup
883 for.cond3.preheader.lr.ph:
884 %cmp636 = icmp sgt i16 %m, 0
885 br i1 %cmp636, label %for.cond3.preheader.us.preheader, label %for.cond3.preheader.preheader
887 for.cond3.preheader.preheader:
888 br label %for.cond3.preheader
890 for.cond3.preheader.us.preheader:
891 br label %for.cond3.preheader.us
893 for.cond3.preheader.us:
894 %i.039.us = phi i16 [ %inc22.us, %for.cond3.for.cond.cleanup8_crit_edge.us ], [ 0, %for.cond3.preheader.us.preheader ]
895 %mul.us = mul i16 %i.039.us, %m
896 br label %for.body9.us
899 %j.037.us = phi i16 [ 0, %for.cond3.preheader.us ], [ %inc.us, %for.body9.us ]
900 %add.us = add i16 %j.037.us, %mul.us
901 %conv14.us = sext i16 %add.us to i32
902 %call.us = tail call i32 @use_32(i32 %conv14.us) #2
903 %call15.us = tail call i32 @use_16(i16 %add.us) #2
904 %call17.us = tail call i32 @use_32(i32 %conv14.us) #2
905 %call18.us = tail call i32 @use_16(i16 %add.us) #2
906 %conv19.us = sext i16 %add.us to i64
907 %call20.us = tail call i32 @use_64(i64 %conv19.us) #2
908 %inc.us = add nuw nsw i16 %j.037.us, 1
909 %cmp6.us = icmp slt i16 %inc.us, %m
910 br i1 %cmp6.us, label %for.body9.us, label %for.cond3.for.cond.cleanup8_crit_edge.us
912 for.cond3.for.cond.cleanup8_crit_edge.us:
913 %inc22.us = add i16 %i.039.us, 1
914 %cmp.us = icmp slt i16 %inc22.us, %n
915 br i1 %cmp.us, label %for.cond3.preheader.us, label %for.cond.cleanup
918 %i.039 = phi i16 [ %inc22, %for.cond3.preheader ], [ 0, %for.cond3.preheader.preheader ]
919 %inc22 = add i16 %i.039, 1
920 %cmp = icmp slt i16 %inc22, %n
921 br i1 %cmp, label %for.cond3.preheader, label %for.cond.cleanup
927 ; Identify trip count when it is constant and the IV has been widened.
928 define i32 @constTripCount() {
929 ; CHECK-LABEL: @constTripCount(
931 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 20, 20
932 ; CHECK-NEXT: br label [[I_LOOP:%.*]]
934 ; CHECK-NEXT: [[INDVAR1:%.*]] = phi i64 [ [[INDVAR_NEXT2:%.*]], [[J_LOOPDONE:%.*]] ], [ 0, [[ENTRY:%.*]] ]
935 ; CHECK-NEXT: br label [[J_LOOP:%.*]]
937 ; CHECK-NEXT: call void @payload()
938 ; CHECK-NEXT: br label [[J_LOOPDONE]]
940 ; CHECK-NEXT: [[INDVAR_NEXT2]] = add i64 [[INDVAR1]], 1
941 ; CHECK-NEXT: [[I_ATEND:%.*]] = icmp eq i64 [[INDVAR_NEXT2]], [[FLATTEN_TRIPCOUNT]]
942 ; CHECK-NEXT: br i1 [[I_ATEND]], label [[I_LOOPDONE:%.*]], label [[I_LOOP]]
944 ; CHECK-NEXT: ret i32 0
946 ; DONTWIDEN-LABEL: @constTripCount(
947 ; DONTWIDEN-NEXT: entry:
948 ; DONTWIDEN-NEXT: br label [[I_LOOP:%.*]]
950 ; DONTWIDEN-NEXT: [[I:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[I_INC:%.*]], [[J_LOOPDONE:%.*]] ]
951 ; DONTWIDEN-NEXT: br label [[J_LOOP:%.*]]
953 ; DONTWIDEN-NEXT: [[J:%.*]] = phi i8 [ 0, [[I_LOOP]] ], [ [[J_INC:%.*]], [[J_LOOP]] ]
954 ; DONTWIDEN-NEXT: call void @payload()
955 ; DONTWIDEN-NEXT: [[J_INC]] = add i8 [[J]], 1
956 ; DONTWIDEN-NEXT: [[J_ATEND:%.*]] = icmp eq i8 [[J_INC]], 20
957 ; DONTWIDEN-NEXT: br i1 [[J_ATEND]], label [[J_LOOPDONE]], label [[J_LOOP]]
958 ; DONTWIDEN: j.loopdone:
959 ; DONTWIDEN-NEXT: [[I_INC]] = add i8 [[I]], 1
960 ; DONTWIDEN-NEXT: [[I_ATEND:%.*]] = icmp eq i8 [[I_INC]], 20
961 ; DONTWIDEN-NEXT: br i1 [[I_ATEND]], label [[I_LOOPDONE:%.*]], label [[I_LOOP]]
962 ; DONTWIDEN: i.loopdone:
963 ; DONTWIDEN-NEXT: ret i32 0
969 %i = phi i8 [ 0, %entry ], [ %i.inc, %j.loopdone ]
973 %j = phi i8 [ 0, %i.loop ], [ %j.inc, %j.loop ]
975 %j.inc = add i8 %j, 1
976 %j.atend = icmp eq i8 %j.inc, 20
977 br i1 %j.atend, label %j.loopdone, label %j.loop
980 %i.inc = add i8 %i, 1
981 %i.atend = icmp eq i8 %i.inc, 20
982 br i1 %i.atend, label %i.loopdone, label %i.loop
988 ; Same as @foo, but M is sext from i16. This used to assert because we thought
989 ; this sext was from widening and try to look through it.
990 define void @foo_M_sext(ptr %A, i32 %N, i16 %M) {
991 ; CHECK-LABEL: @foo_M_sext(
993 ; CHECK-NEXT: [[M2:%.*]] = sext i16 [[M:%.*]] to i32
994 ; CHECK-NEXT: [[CMP17:%.*]] = icmp sgt i32 [[N:%.*]], 0
995 ; CHECK-NEXT: br i1 [[CMP17]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]], label [[FOR_COND_CLEANUP:%.*]]
996 ; CHECK: for.cond1.preheader.lr.ph:
997 ; CHECK-NEXT: [[CMP215:%.*]] = icmp sgt i32 [[M2]], 0
998 ; CHECK-NEXT: br i1 [[CMP215]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]], label [[FOR_COND_CLEANUP]]
999 ; CHECK: for.cond1.preheader.us.preheader:
1000 ; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[M2]] to i64
1001 ; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[N]] to i64
1002 ; CHECK-NEXT: [[FLATTEN_TRIPCOUNT:%.*]] = mul i64 [[TMP0]], [[TMP1]]
1003 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
1004 ; CHECK: for.cond1.preheader.us:
1005 ; CHECK-NEXT: [[INDVAR1:%.*]] = phi i64 [ [[INDVAR_NEXT2:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
1006 ; CHECK-NEXT: [[FLATTEN_TRUNCIV:%.*]] = trunc i64 [[INDVAR1]] to i32
1007 ; CHECK-NEXT: br label [[FOR_BODY4_US:%.*]]
1008 ; CHECK: for.body4.us:
1009 ; CHECK-NEXT: [[IDXPROM_US:%.*]] = sext i32 [[FLATTEN_TRUNCIV]] to i64
1010 ; CHECK-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[IDXPROM_US]]
1011 ; CHECK-NEXT: tail call void @f(ptr [[ARRAYIDX_US]])
1012 ; CHECK-NEXT: br label [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US]]
1013 ; CHECK: for.cond1.for.cond.cleanup3_crit_edge.us:
1014 ; CHECK-NEXT: [[INDVAR_NEXT2]] = add i64 [[INDVAR1]], 1
1015 ; CHECK-NEXT: [[CMP_US:%.*]] = icmp slt i64 [[INDVAR_NEXT2]], [[FLATTEN_TRIPCOUNT]]
1016 ; CHECK-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
1017 ; CHECK: for.cond.cleanup.loopexit:
1018 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
1019 ; CHECK: for.cond.cleanup:
1020 ; CHECK-NEXT: ret void
1022 ; DONTWIDEN-LABEL: @foo_M_sext(
1023 ; DONTWIDEN-NEXT: entry:
1024 ; DONTWIDEN-NEXT: [[M2:%.*]] = sext i16 [[M:%.*]] to i32
1025 ; DONTWIDEN-NEXT: [[CMP17:%.*]] = icmp sgt i32 [[N:%.*]], 0
1026 ; DONTWIDEN-NEXT: br i1 [[CMP17]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]], label [[FOR_COND_CLEANUP:%.*]]
1027 ; DONTWIDEN: for.cond1.preheader.lr.ph:
1028 ; DONTWIDEN-NEXT: [[CMP215:%.*]] = icmp sgt i32 [[M2]], 0
1029 ; DONTWIDEN-NEXT: br i1 [[CMP215]], label [[FOR_COND1_PREHEADER_US_PREHEADER:%.*]], label [[FOR_COND_CLEANUP]]
1030 ; DONTWIDEN: for.cond1.preheader.us.preheader:
1031 ; DONTWIDEN-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
1032 ; DONTWIDEN: for.cond1.preheader.us:
1033 ; DONTWIDEN-NEXT: [[I_018_US:%.*]] = phi i32 [ [[INC6_US:%.*]], [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US:%.*]] ], [ 0, [[FOR_COND1_PREHEADER_US_PREHEADER]] ]
1034 ; DONTWIDEN-NEXT: [[MUL_US:%.*]] = mul nsw i32 [[I_018_US]], [[M2]]
1035 ; DONTWIDEN-NEXT: br label [[FOR_BODY4_US:%.*]]
1036 ; DONTWIDEN: for.body4.us:
1037 ; DONTWIDEN-NEXT: [[J_016_US:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_US]] ], [ [[INC_US:%.*]], [[FOR_BODY4_US]] ]
1038 ; DONTWIDEN-NEXT: [[ADD_US:%.*]] = add nsw i32 [[J_016_US]], [[MUL_US]]
1039 ; DONTWIDEN-NEXT: [[IDXPROM_US:%.*]] = sext i32 [[ADD_US]] to i64
1040 ; DONTWIDEN-NEXT: [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[IDXPROM_US]]
1041 ; DONTWIDEN-NEXT: tail call void @f(ptr [[ARRAYIDX_US]])
1042 ; DONTWIDEN-NEXT: [[INC_US]] = add nuw nsw i32 [[J_016_US]], 1
1043 ; DONTWIDEN-NEXT: [[CMP2_US:%.*]] = icmp slt i32 [[INC_US]], [[M2]]
1044 ; DONTWIDEN-NEXT: br i1 [[CMP2_US]], label [[FOR_BODY4_US]], label [[FOR_COND1_FOR_COND_CLEANUP3_CRIT_EDGE_US]]
1045 ; DONTWIDEN: for.cond1.for.cond.cleanup3_crit_edge.us:
1046 ; DONTWIDEN-NEXT: [[INC6_US]] = add nuw nsw i32 [[I_018_US]], 1
1047 ; DONTWIDEN-NEXT: [[CMP_US:%.*]] = icmp slt i32 [[INC6_US]], [[N]]
1048 ; DONTWIDEN-NEXT: br i1 [[CMP_US]], label [[FOR_COND1_PREHEADER_US]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
1049 ; DONTWIDEN: for.cond.cleanup.loopexit:
1050 ; DONTWIDEN-NEXT: br label [[FOR_COND_CLEANUP]]
1051 ; DONTWIDEN: for.cond.cleanup:
1052 ; DONTWIDEN-NEXT: ret void
1055 %M2 = sext i16 %M to i32
1056 %cmp17 = icmp sgt i32 %N, 0
1057 br i1 %cmp17, label %for.cond1.preheader.lr.ph, label %for.cond.cleanup
1059 for.cond1.preheader.lr.ph:
1060 %cmp215 = icmp sgt i32 %M2, 0
1061 br i1 %cmp215, label %for.cond1.preheader.us.preheader, label %for.cond.cleanup
1063 for.cond1.preheader.us.preheader:
1064 br label %for.cond1.preheader.us
1066 for.cond1.preheader.us:
1067 %i.018.us = phi i32 [ %inc6.us, %for.cond1.for.cond.cleanup3_crit_edge.us ], [ 0, %for.cond1.preheader.us.preheader ]
1068 %mul.us = mul nsw i32 %i.018.us, %M2
1069 br label %for.body4.us
1072 %j.016.us = phi i32 [ 0, %for.cond1.preheader.us ], [ %inc.us, %for.body4.us ]
1073 %add.us = add nsw i32 %j.016.us, %mul.us
1074 %idxprom.us = sext i32 %add.us to i64
1075 %arrayidx.us = getelementptr inbounds i32, ptr %A, i64 %idxprom.us
1076 tail call void @f(ptr %arrayidx.us) #2
1077 %inc.us = add nuw nsw i32 %j.016.us, 1
1078 %cmp2.us = icmp slt i32 %inc.us, %M2
1079 br i1 %cmp2.us, label %for.body4.us, label %for.cond1.for.cond.cleanup3_crit_edge.us
1081 for.cond1.for.cond.cleanup3_crit_edge.us:
1082 %inc6.us = add nuw nsw i32 %i.018.us, 1
1083 %cmp.us = icmp slt i32 %inc6.us, %N
1084 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.cond.cleanup
1090 declare void @payload()
1091 declare dso_local i32 @use_32(i32)
1092 declare dso_local i32 @use_16(i16)
1093 declare dso_local i32 @use_64(i64)
1094 declare dso_local void @g(i32)
1096 declare dso_local void @f(ptr %0) local_unnamed_addr #1