1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -S < %s 2>&1 | FileCheck %s
3 ; RUN: opt -verify-loop-info -irce-print-changed-loops -passes='require<branch-prob>,loop(irce)' -S < %s 2>&1 | FileCheck %s
5 ; CHECK-NOT: irce: in function test_01: constrained Loop
6 ; CHECK-NOT: irce: in function test_02: constrained Loop
7 ; CHECK: irce: in function test_03: constrained Loop
9 ; RC against known negative value. We should not do IRCE here.
10 define void @test_01(i32 *%arr, i32 %n) {
11 ; CHECK-LABEL: @test_01(
13 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
14 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
15 ; CHECK: loop.preheader:
16 ; CHECK-NEXT: br label [[LOOP:%.*]]
18 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
19 ; CHECK-NEXT: [[IDX_NEXT]] = add i32 [[IDX]], 1
20 ; CHECK-NEXT: [[ABC:%.*]] = icmp slt i32 [[IDX]], -9
21 ; CHECK-NEXT: br i1 [[ABC]], label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS:%.*]], !prof !0
23 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr i32, i32* [[ARR:%.*]], i32 [[IDX]]
24 ; CHECK-NEXT: store i32 0, i32* [[ADDR]]
25 ; CHECK-NEXT: [[NEXT:%.*]] = icmp slt i32 [[IDX_NEXT]], [[N]]
26 ; CHECK-NEXT: br i1 [[NEXT]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
27 ; CHECK: out.of.bounds:
28 ; CHECK-NEXT: ret void
29 ; CHECK: exit.loopexit:
30 ; CHECK-NEXT: br label [[EXIT]]
32 ; CHECK-NEXT: ret void
36 %first.itr.check = icmp sgt i32 %n, 0
37 br i1 %first.itr.check, label %loop, label %exit
40 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
41 %idx.next = add i32 %idx, 1
42 %abc = icmp slt i32 %idx, -9
43 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !0
46 %addr = getelementptr i32, i32* %arr, i32 %idx
47 store i32 0, i32* %addr
48 %next = icmp slt i32 %idx.next, %n
49 br i1 %next, label %loop, label %exit
58 ; Same as test_01, but the latch condition is unsigned.
59 define void @test_02(i32 *%arr, i32 %n) {
60 ; CHECK-LABEL: @test_02(
62 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
63 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
64 ; CHECK: loop.preheader:
65 ; CHECK-NEXT: br label [[LOOP:%.*]]
67 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
68 ; CHECK-NEXT: [[IDX_NEXT]] = add i32 [[IDX]], 1
69 ; CHECK-NEXT: [[ABC:%.*]] = icmp slt i32 [[IDX]], -9
70 ; CHECK-NEXT: br i1 [[ABC]], label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS:%.*]], !prof !0
72 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr i32, i32* [[ARR:%.*]], i32 [[IDX]]
73 ; CHECK-NEXT: store i32 0, i32* [[ADDR]]
74 ; CHECK-NEXT: [[NEXT:%.*]] = icmp ult i32 [[IDX_NEXT]], [[N]]
75 ; CHECK-NEXT: br i1 [[NEXT]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
76 ; CHECK: out.of.bounds:
77 ; CHECK-NEXT: ret void
78 ; CHECK: exit.loopexit:
79 ; CHECK-NEXT: br label [[EXIT]]
81 ; CHECK-NEXT: ret void
85 %first.itr.check = icmp sgt i32 %n, 0
86 br i1 %first.itr.check, label %loop, label %exit
89 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
90 %idx.next = add i32 %idx, 1
91 %abc = icmp slt i32 %idx, -9
92 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !0
95 %addr = getelementptr i32, i32* %arr, i32 %idx
96 store i32 0, i32* %addr
97 %next = icmp ult i32 %idx.next, %n
98 br i1 %next, label %loop, label %exit
107 ; RC against a value which is not known to be non-negative. Here we should
108 ; expand runtime checks against bound being positive or negative.
109 define void @test_03(i32 *%arr, i32 %n, i32 %bound) {
110 ; CHECK-LABEL: @test_03(
112 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
113 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
114 ; CHECK: loop.preheader:
115 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[BOUND:%.*]], -2147483647
116 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 0
117 ; CHECK-NEXT: [[SMAX:%.*]] = select i1 [[TMP1]], i32 [[TMP0]], i32 0
118 ; CHECK-NEXT: [[TMP2:%.*]] = sub i32 [[BOUND]], [[SMAX]]
119 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[BOUND]], 0
120 ; CHECK-NEXT: [[SMIN:%.*]] = select i1 [[TMP3]], i32 [[BOUND]], i32 0
121 ; CHECK-NEXT: [[TMP4:%.*]] = icmp sgt i32 [[SMIN]], -1
122 ; CHECK-NEXT: [[SMAX1:%.*]] = select i1 [[TMP4]], i32 [[SMIN]], i32 -1
123 ; CHECK-NEXT: [[TMP5:%.*]] = add nsw i32 [[SMAX1]], 1
124 ; CHECK-NEXT: [[TMP6:%.*]] = mul i32 [[TMP2]], [[TMP5]]
125 ; CHECK-NEXT: [[TMP7:%.*]] = icmp slt i32 [[N]], [[TMP6]]
126 ; CHECK-NEXT: [[SMIN2:%.*]] = select i1 [[TMP7]], i32 [[N]], i32 [[TMP6]]
127 ; CHECK-NEXT: [[TMP8:%.*]] = icmp sgt i32 [[SMIN2]], 0
128 ; CHECK-NEXT: [[EXIT_MAINLOOP_AT:%.*]] = select i1 [[TMP8]], i32 [[SMIN2]], i32 0
129 ; CHECK-NEXT: [[TMP9:%.*]] = icmp slt i32 0, [[EXIT_MAINLOOP_AT]]
130 ; CHECK-NEXT: br i1 [[TMP9]], label [[LOOP_PREHEADER4:%.*]], label [[MAIN_PSEUDO_EXIT:%.*]]
131 ; CHECK: loop.preheader4:
132 ; CHECK-NEXT: br label [[LOOP:%.*]]
134 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER4]] ]
135 ; CHECK-NEXT: [[IDX_NEXT]] = add i32 [[IDX]], 1
136 ; CHECK-NEXT: [[ABC:%.*]] = icmp slt i32 [[IDX]], [[BOUND]]
137 ; CHECK-NEXT: br i1 true, label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS_LOOPEXIT5:%.*]], !prof !0
139 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr i32, i32* [[ARR:%.*]], i32 [[IDX]]
140 ; CHECK-NEXT: store i32 0, i32* [[ADDR]]
141 ; CHECK-NEXT: [[NEXT:%.*]] = icmp slt i32 [[IDX_NEXT]], [[N]]
142 ; CHECK-NEXT: [[TMP10:%.*]] = icmp slt i32 [[IDX_NEXT]], [[EXIT_MAINLOOP_AT]]
143 ; CHECK-NEXT: br i1 [[TMP10]], label [[LOOP]], label [[MAIN_EXIT_SELECTOR:%.*]]
144 ; CHECK: main.exit.selector:
145 ; CHECK-NEXT: [[IDX_NEXT_LCSSA:%.*]] = phi i32 [ [[IDX_NEXT]], [[IN_BOUNDS]] ]
146 ; CHECK-NEXT: [[TMP11:%.*]] = icmp slt i32 [[IDX_NEXT_LCSSA]], [[N]]
147 ; CHECK-NEXT: br i1 [[TMP11]], label [[MAIN_PSEUDO_EXIT]], label [[EXIT_LOOPEXIT:%.*]]
148 ; CHECK: main.pseudo.exit:
149 ; CHECK-NEXT: [[IDX_COPY:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
150 ; CHECK-NEXT: [[INDVAR_END:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
151 ; CHECK-NEXT: br label [[POSTLOOP:%.*]]
152 ; CHECK: out.of.bounds.loopexit:
153 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS:%.*]]
154 ; CHECK: out.of.bounds.loopexit5:
155 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS]]
156 ; CHECK: out.of.bounds:
157 ; CHECK-NEXT: ret void
158 ; CHECK: exit.loopexit.loopexit:
159 ; CHECK-NEXT: br label [[EXIT_LOOPEXIT]]
160 ; CHECK: exit.loopexit:
161 ; CHECK-NEXT: br label [[EXIT]]
163 ; CHECK-NEXT: ret void
165 ; CHECK-NEXT: br label [[LOOP_POSTLOOP:%.*]]
166 ; CHECK: loop.postloop:
167 ; CHECK-NEXT: [[IDX_POSTLOOP:%.*]] = phi i32 [ [[IDX_NEXT_POSTLOOP:%.*]], [[IN_BOUNDS_POSTLOOP:%.*]] ], [ [[IDX_COPY]], [[POSTLOOP]] ]
168 ; CHECK-NEXT: [[IDX_NEXT_POSTLOOP]] = add i32 [[IDX_POSTLOOP]], 1
169 ; CHECK-NEXT: [[ABC_POSTLOOP:%.*]] = icmp slt i32 [[IDX_POSTLOOP]], [[BOUND]]
170 ; CHECK-NEXT: br i1 [[ABC_POSTLOOP]], label [[IN_BOUNDS_POSTLOOP]], label [[OUT_OF_BOUNDS_LOOPEXIT:%.*]], !prof !0
171 ; CHECK: in.bounds.postloop:
172 ; CHECK-NEXT: [[ADDR_POSTLOOP:%.*]] = getelementptr i32, i32* [[ARR]], i32 [[IDX_POSTLOOP]]
173 ; CHECK-NEXT: store i32 0, i32* [[ADDR_POSTLOOP]]
174 ; CHECK-NEXT: [[NEXT_POSTLOOP:%.*]] = icmp slt i32 [[IDX_NEXT_POSTLOOP]], [[N]]
175 ; CHECK-NEXT: br i1 [[NEXT_POSTLOOP]], label [[LOOP_POSTLOOP]], label [[EXIT_LOOPEXIT_LOOPEXIT:%.*]], !llvm.loop !1, !irce.loop.clone !6
179 %first.itr.check = icmp sgt i32 %n, 0
180 br i1 %first.itr.check, label %loop, label %exit
183 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
184 %idx.next = add i32 %idx, 1
185 %abc = icmp slt i32 %idx, %bound
186 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !0
189 %addr = getelementptr i32, i32* %arr, i32 %idx
190 store i32 0, i32* %addr
191 %next = icmp slt i32 %idx.next, %n
192 br i1 %next, label %loop, label %exit
201 ; RC against a value which is not known to be non-negative. Here we should
202 ; expand runtime checks against bound being positive or negative.
203 define void @test_04(i32 *%arr, i32 %n, i32 %bound) {
204 ; CHECK-LABEL: @test_04(
206 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
207 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
208 ; CHECK: loop.preheader:
209 ; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[BOUND:%.*]], 0
210 ; CHECK-NEXT: [[SMIN:%.*]] = select i1 [[TMP0]], i32 [[BOUND]], i32 0
211 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[BOUND]], [[SMIN]]
212 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[SMIN]], -1
213 ; CHECK-NEXT: [[SMAX:%.*]] = select i1 [[TMP2]], i32 [[SMIN]], i32 -1
214 ; CHECK-NEXT: [[TMP3:%.*]] = add nsw i32 [[SMAX]], 1
215 ; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP1]], [[TMP3]]
216 ; CHECK-NEXT: [[TMP5:%.*]] = icmp ult i32 [[N]], [[TMP4]]
217 ; CHECK-NEXT: [[EXIT_MAINLOOP_AT:%.*]] = select i1 [[TMP5]], i32 [[N]], i32 [[TMP4]]
218 ; CHECK-NEXT: [[TMP6:%.*]] = icmp ult i32 0, [[EXIT_MAINLOOP_AT]]
219 ; CHECK-NEXT: br i1 [[TMP6]], label [[LOOP_PREHEADER1:%.*]], label [[MAIN_PSEUDO_EXIT:%.*]]
220 ; CHECK: loop.preheader1:
221 ; CHECK-NEXT: br label [[LOOP:%.*]]
223 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER1]] ]
224 ; CHECK-NEXT: [[IDX_NEXT]] = add i32 [[IDX]], 1
225 ; CHECK-NEXT: [[ABC:%.*]] = icmp slt i32 [[IDX]], [[BOUND]]
226 ; CHECK-NEXT: br i1 true, label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS_LOOPEXIT2:%.*]], !prof !0
228 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr i32, i32* [[ARR:%.*]], i32 [[IDX]]
229 ; CHECK-NEXT: store i32 0, i32* [[ADDR]]
230 ; CHECK-NEXT: [[NEXT:%.*]] = icmp ult i32 [[IDX_NEXT]], [[N]]
231 ; CHECK-NEXT: [[TMP7:%.*]] = icmp ult i32 [[IDX_NEXT]], [[EXIT_MAINLOOP_AT]]
232 ; CHECK-NEXT: br i1 [[TMP7]], label [[LOOP]], label [[MAIN_EXIT_SELECTOR:%.*]]
233 ; CHECK: main.exit.selector:
234 ; CHECK-NEXT: [[IDX_NEXT_LCSSA:%.*]] = phi i32 [ [[IDX_NEXT]], [[IN_BOUNDS]] ]
235 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ult i32 [[IDX_NEXT_LCSSA]], [[N]]
236 ; CHECK-NEXT: br i1 [[TMP8]], label [[MAIN_PSEUDO_EXIT]], label [[EXIT_LOOPEXIT:%.*]]
237 ; CHECK: main.pseudo.exit:
238 ; CHECK-NEXT: [[IDX_COPY:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
239 ; CHECK-NEXT: [[INDVAR_END:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
240 ; CHECK-NEXT: br label [[POSTLOOP:%.*]]
241 ; CHECK: out.of.bounds.loopexit:
242 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS:%.*]]
243 ; CHECK: out.of.bounds.loopexit2:
244 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS]]
245 ; CHECK: out.of.bounds:
246 ; CHECK-NEXT: ret void
247 ; CHECK: exit.loopexit.loopexit:
248 ; CHECK-NEXT: br label [[EXIT_LOOPEXIT]]
249 ; CHECK: exit.loopexit:
250 ; CHECK-NEXT: br label [[EXIT]]
252 ; CHECK-NEXT: ret void
254 ; CHECK-NEXT: br label [[LOOP_POSTLOOP:%.*]]
255 ; CHECK: loop.postloop:
256 ; CHECK-NEXT: [[IDX_POSTLOOP:%.*]] = phi i32 [ [[IDX_NEXT_POSTLOOP:%.*]], [[IN_BOUNDS_POSTLOOP:%.*]] ], [ [[IDX_COPY]], [[POSTLOOP]] ]
257 ; CHECK-NEXT: [[IDX_NEXT_POSTLOOP]] = add i32 [[IDX_POSTLOOP]], 1
258 ; CHECK-NEXT: [[ABC_POSTLOOP:%.*]] = icmp slt i32 [[IDX_POSTLOOP]], [[BOUND]]
259 ; CHECK-NEXT: br i1 [[ABC_POSTLOOP]], label [[IN_BOUNDS_POSTLOOP]], label [[OUT_OF_BOUNDS_LOOPEXIT:%.*]], !prof !0
260 ; CHECK: in.bounds.postloop:
261 ; CHECK-NEXT: [[ADDR_POSTLOOP:%.*]] = getelementptr i32, i32* [[ARR]], i32 [[IDX_POSTLOOP]]
262 ; CHECK-NEXT: store i32 0, i32* [[ADDR_POSTLOOP]]
263 ; CHECK-NEXT: [[NEXT_POSTLOOP:%.*]] = icmp ult i32 [[IDX_NEXT_POSTLOOP]], [[N]]
264 ; CHECK-NEXT: br i1 [[NEXT_POSTLOOP]], label [[LOOP_POSTLOOP]], label [[EXIT_LOOPEXIT_LOOPEXIT:%.*]], !llvm.loop !7, !irce.loop.clone !6
268 %first.itr.check = icmp sgt i32 %n, 0
269 br i1 %first.itr.check, label %loop, label %exit
272 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
273 %idx.next = add i32 %idx, 1
274 %abc = icmp slt i32 %idx, %bound
275 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !0
278 %addr = getelementptr i32, i32* %arr, i32 %idx
279 store i32 0, i32* %addr
280 %next = icmp ult i32 %idx.next, %n
281 br i1 %next, label %loop, label %exit
290 ; Same as test_01, unsigned range check.
291 ; FIXME: We could remove the range check here, but it does not happen due to the
292 ; limintation we posed to fix the miscompile (see comments in the method
293 ; computeSafeIterationSpace).
294 define void @test_05(i32 *%arr, i32 %n) {
295 ; CHECK-LABEL: @test_05(
297 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
298 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
299 ; CHECK: loop.preheader:
300 ; CHECK-NEXT: br label [[LOOP:%.*]]
302 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
303 ; CHECK-NEXT: [[IDX_NEXT]] = add i32 [[IDX]], 1
304 ; CHECK-NEXT: [[ABC:%.*]] = icmp ult i32 [[IDX]], -9
305 ; CHECK-NEXT: br i1 [[ABC]], label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS:%.*]], !prof !0
307 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr i32, i32* [[ARR:%.*]], i32 [[IDX]]
308 ; CHECK-NEXT: store i32 0, i32* [[ADDR]]
309 ; CHECK-NEXT: [[NEXT:%.*]] = icmp slt i32 [[IDX_NEXT]], [[N]]
310 ; CHECK-NEXT: br i1 [[NEXT]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
311 ; CHECK: out.of.bounds:
312 ; CHECK-NEXT: ret void
313 ; CHECK: exit.loopexit:
314 ; CHECK-NEXT: br label [[EXIT]]
316 ; CHECK-NEXT: ret void
319 %first.itr.check = icmp sgt i32 %n, 0
320 br i1 %first.itr.check, label %loop, label %exit
323 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
324 %idx.next = add i32 %idx, 1
325 %abc = icmp ult i32 %idx, -9
326 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !0
329 %addr = getelementptr i32, i32* %arr, i32 %idx
330 store i32 0, i32* %addr
331 %next = icmp slt i32 %idx.next, %n
332 br i1 %next, label %loop, label %exit
341 ; Same as test_02, unsigned range check.
342 ; FIXME: We could remove the range check here, but it does not happen due to the
343 ; limintation we posed to fix the miscompile (see comments in the method
344 ; computeSafeIterationSpace).
345 define void @test_06(i32 *%arr, i32 %n) {
346 ; CHECK-LABEL: @test_06(
348 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
349 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
350 ; CHECK: loop.preheader:
351 ; CHECK-NEXT: br label [[LOOP:%.*]]
353 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
354 ; CHECK-NEXT: [[IDX_NEXT]] = add i32 [[IDX]], 1
355 ; CHECK-NEXT: [[ABC:%.*]] = icmp ult i32 [[IDX]], -9
356 ; CHECK-NEXT: br i1 [[ABC]], label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS:%.*]], !prof !0
358 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr i32, i32* [[ARR:%.*]], i32 [[IDX]]
359 ; CHECK-NEXT: store i32 0, i32* [[ADDR]]
360 ; CHECK-NEXT: [[NEXT:%.*]] = icmp ult i32 [[IDX_NEXT]], [[N]]
361 ; CHECK-NEXT: br i1 [[NEXT]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
362 ; CHECK: out.of.bounds:
363 ; CHECK-NEXT: ret void
364 ; CHECK: exit.loopexit:
365 ; CHECK-NEXT: br label [[EXIT]]
367 ; CHECK-NEXT: ret void
370 %first.itr.check = icmp sgt i32 %n, 0
371 br i1 %first.itr.check, label %loop, label %exit
374 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
375 %idx.next = add i32 %idx, 1
376 %abc = icmp ult i32 %idx, -9
377 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !0
380 %addr = getelementptr i32, i32* %arr, i32 %idx
381 store i32 0, i32* %addr
382 %next = icmp ult i32 %idx.next, %n
383 br i1 %next, label %loop, label %exit
392 ; Same as test_03, unsigned range check.
393 ; FIXME: Currently we remove the check, but we will not execute the main loop if
394 ; %bound is negative (i.e. in [SINT_MAX + 1, UINT_MAX)). We should be able to
395 ; safely remove this check (see comments in the method
396 ; computeSafeIterationSpace).
397 define void @test_07(i32 *%arr, i32 %n, i32 %bound) {
398 ; CHECK-LABEL: @test_07(
400 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
401 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
402 ; CHECK: loop.preheader:
403 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[BOUND:%.*]], -2147483647
404 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[TMP0]], 0
405 ; CHECK-NEXT: [[SMAX:%.*]] = select i1 [[TMP1]], i32 [[TMP0]], i32 0
406 ; CHECK-NEXT: [[TMP2:%.*]] = sub i32 [[BOUND]], [[SMAX]]
407 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[BOUND]], 0
408 ; CHECK-NEXT: [[SMIN:%.*]] = select i1 [[TMP3]], i32 [[BOUND]], i32 0
409 ; CHECK-NEXT: [[TMP4:%.*]] = icmp sgt i32 [[SMIN]], -1
410 ; CHECK-NEXT: [[SMAX1:%.*]] = select i1 [[TMP4]], i32 [[SMIN]], i32 -1
411 ; CHECK-NEXT: [[TMP5:%.*]] = add nsw i32 [[SMAX1]], 1
412 ; CHECK-NEXT: [[TMP6:%.*]] = mul i32 [[TMP2]], [[TMP5]]
413 ; CHECK-NEXT: [[TMP7:%.*]] = icmp slt i32 [[N]], [[TMP6]]
414 ; CHECK-NEXT: [[SMIN2:%.*]] = select i1 [[TMP7]], i32 [[N]], i32 [[TMP6]]
415 ; CHECK-NEXT: [[TMP8:%.*]] = icmp sgt i32 [[SMIN2]], 0
416 ; CHECK-NEXT: [[EXIT_MAINLOOP_AT:%.*]] = select i1 [[TMP8]], i32 [[SMIN2]], i32 0
417 ; CHECK-NEXT: [[TMP9:%.*]] = icmp slt i32 0, [[EXIT_MAINLOOP_AT]]
418 ; CHECK-NEXT: br i1 [[TMP9]], label [[LOOP_PREHEADER4:%.*]], label [[MAIN_PSEUDO_EXIT:%.*]]
419 ; CHECK: loop.preheader4:
420 ; CHECK-NEXT: br label [[LOOP:%.*]]
422 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER4]] ]
423 ; CHECK-NEXT: [[IDX_NEXT]] = add i32 [[IDX]], 1
424 ; CHECK-NEXT: [[ABC:%.*]] = icmp ult i32 [[IDX]], [[BOUND]]
425 ; CHECK-NEXT: br i1 true, label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS_LOOPEXIT5:%.*]], !prof !0
427 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr i32, i32* [[ARR:%.*]], i32 [[IDX]]
428 ; CHECK-NEXT: store i32 0, i32* [[ADDR]]
429 ; CHECK-NEXT: [[NEXT:%.*]] = icmp slt i32 [[IDX_NEXT]], [[N]]
430 ; CHECK-NEXT: [[TMP10:%.*]] = icmp slt i32 [[IDX_NEXT]], [[EXIT_MAINLOOP_AT]]
431 ; CHECK-NEXT: br i1 [[TMP10]], label [[LOOP]], label [[MAIN_EXIT_SELECTOR:%.*]]
432 ; CHECK: main.exit.selector:
433 ; CHECK-NEXT: [[IDX_NEXT_LCSSA:%.*]] = phi i32 [ [[IDX_NEXT]], [[IN_BOUNDS]] ]
434 ; CHECK-NEXT: [[TMP11:%.*]] = icmp slt i32 [[IDX_NEXT_LCSSA]], [[N]]
435 ; CHECK-NEXT: br i1 [[TMP11]], label [[MAIN_PSEUDO_EXIT]], label [[EXIT_LOOPEXIT:%.*]]
436 ; CHECK: main.pseudo.exit:
437 ; CHECK-NEXT: [[IDX_COPY:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
438 ; CHECK-NEXT: [[INDVAR_END:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
439 ; CHECK-NEXT: br label [[POSTLOOP:%.*]]
440 ; CHECK: out.of.bounds.loopexit:
441 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS:%.*]]
442 ; CHECK: out.of.bounds.loopexit5:
443 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS]]
444 ; CHECK: out.of.bounds:
445 ; CHECK-NEXT: ret void
446 ; CHECK: exit.loopexit.loopexit:
447 ; CHECK-NEXT: br label [[EXIT_LOOPEXIT]]
448 ; CHECK: exit.loopexit:
449 ; CHECK-NEXT: br label [[EXIT]]
451 ; CHECK-NEXT: ret void
453 ; CHECK-NEXT: br label [[LOOP_POSTLOOP:%.*]]
454 ; CHECK: loop.postloop:
455 ; CHECK-NEXT: [[IDX_POSTLOOP:%.*]] = phi i32 [ [[IDX_NEXT_POSTLOOP:%.*]], [[IN_BOUNDS_POSTLOOP:%.*]] ], [ [[IDX_COPY]], [[POSTLOOP]] ]
456 ; CHECK-NEXT: [[IDX_NEXT_POSTLOOP]] = add i32 [[IDX_POSTLOOP]], 1
457 ; CHECK-NEXT: [[ABC_POSTLOOP:%.*]] = icmp ult i32 [[IDX_POSTLOOP]], [[BOUND]]
458 ; CHECK-NEXT: br i1 [[ABC_POSTLOOP]], label [[IN_BOUNDS_POSTLOOP]], label [[OUT_OF_BOUNDS_LOOPEXIT:%.*]], !prof !0
459 ; CHECK: in.bounds.postloop:
460 ; CHECK-NEXT: [[ADDR_POSTLOOP:%.*]] = getelementptr i32, i32* [[ARR]], i32 [[IDX_POSTLOOP]]
461 ; CHECK-NEXT: store i32 0, i32* [[ADDR_POSTLOOP]]
462 ; CHECK-NEXT: [[NEXT_POSTLOOP:%.*]] = icmp slt i32 [[IDX_NEXT_POSTLOOP]], [[N]]
463 ; CHECK-NEXT: br i1 [[NEXT_POSTLOOP]], label [[LOOP_POSTLOOP]], label [[EXIT_LOOPEXIT_LOOPEXIT:%.*]], !llvm.loop !8, !irce.loop.clone !6
466 %first.itr.check = icmp sgt i32 %n, 0
467 br i1 %first.itr.check, label %loop, label %exit
470 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
471 %idx.next = add i32 %idx, 1
472 %abc = icmp ult i32 %idx, %bound
473 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !0
476 %addr = getelementptr i32, i32* %arr, i32 %idx
477 store i32 0, i32* %addr
478 %next = icmp slt i32 %idx.next, %n
479 br i1 %next, label %loop, label %exit
488 ; Same as test_04, unsigned range check.
489 ; FIXME: Currently we remove the check, but we will not execute the main loop if
490 ; %bound is negative (i.e. in [SINT_MAX + 1, UINT_MAX)). We should be able to
491 ; safely remove this check (see comments in the method
492 ; computeSafeIterationSpace).
493 define void @test_08(i32 *%arr, i32 %n, i32 %bound) {
494 ; CHECK-LABEL: @test_08(
496 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
497 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
498 ; CHECK: loop.preheader:
499 ; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[BOUND:%.*]], 0
500 ; CHECK-NEXT: [[SMIN:%.*]] = select i1 [[TMP0]], i32 [[BOUND]], i32 0
501 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[BOUND]], [[SMIN]]
502 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[SMIN]], -1
503 ; CHECK-NEXT: [[SMAX:%.*]] = select i1 [[TMP2]], i32 [[SMIN]], i32 -1
504 ; CHECK-NEXT: [[TMP3:%.*]] = add nsw i32 [[SMAX]], 1
505 ; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP1]], [[TMP3]]
506 ; CHECK-NEXT: [[TMP5:%.*]] = icmp ult i32 [[N]], [[TMP4]]
507 ; CHECK-NEXT: [[EXIT_MAINLOOP_AT:%.*]] = select i1 [[TMP5]], i32 [[N]], i32 [[TMP4]]
508 ; CHECK-NEXT: [[TMP6:%.*]] = icmp ult i32 0, [[EXIT_MAINLOOP_AT]]
509 ; CHECK-NEXT: br i1 [[TMP6]], label [[LOOP_PREHEADER1:%.*]], label [[MAIN_PSEUDO_EXIT:%.*]]
510 ; CHECK: loop.preheader1:
511 ; CHECK-NEXT: br label [[LOOP:%.*]]
513 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS:%.*]] ], [ 0, [[LOOP_PREHEADER1]] ]
514 ; CHECK-NEXT: [[IDX_NEXT]] = add i32 [[IDX]], 1
515 ; CHECK-NEXT: [[ABC:%.*]] = icmp ult i32 [[IDX]], [[BOUND]]
516 ; CHECK-NEXT: br i1 true, label [[IN_BOUNDS]], label [[OUT_OF_BOUNDS_LOOPEXIT2:%.*]], !prof !0
518 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr i32, i32* [[ARR:%.*]], i32 [[IDX]]
519 ; CHECK-NEXT: store i32 0, i32* [[ADDR]]
520 ; CHECK-NEXT: [[NEXT:%.*]] = icmp ult i32 [[IDX_NEXT]], [[N]]
521 ; CHECK-NEXT: [[TMP7:%.*]] = icmp ult i32 [[IDX_NEXT]], [[EXIT_MAINLOOP_AT]]
522 ; CHECK-NEXT: br i1 [[TMP7]], label [[LOOP]], label [[MAIN_EXIT_SELECTOR:%.*]]
523 ; CHECK: main.exit.selector:
524 ; CHECK-NEXT: [[IDX_NEXT_LCSSA:%.*]] = phi i32 [ [[IDX_NEXT]], [[IN_BOUNDS]] ]
525 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ult i32 [[IDX_NEXT_LCSSA]], [[N]]
526 ; CHECK-NEXT: br i1 [[TMP8]], label [[MAIN_PSEUDO_EXIT]], label [[EXIT_LOOPEXIT:%.*]]
527 ; CHECK: main.pseudo.exit:
528 ; CHECK-NEXT: [[IDX_COPY:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
529 ; CHECK-NEXT: [[INDVAR_END:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
530 ; CHECK-NEXT: br label [[POSTLOOP:%.*]]
531 ; CHECK: out.of.bounds.loopexit:
532 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS:%.*]]
533 ; CHECK: out.of.bounds.loopexit2:
534 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS]]
535 ; CHECK: out.of.bounds:
536 ; CHECK-NEXT: ret void
537 ; CHECK: exit.loopexit.loopexit:
538 ; CHECK-NEXT: br label [[EXIT_LOOPEXIT]]
539 ; CHECK: exit.loopexit:
540 ; CHECK-NEXT: br label [[EXIT]]
542 ; CHECK-NEXT: ret void
544 ; CHECK-NEXT: br label [[LOOP_POSTLOOP:%.*]]
545 ; CHECK: loop.postloop:
546 ; CHECK-NEXT: [[IDX_POSTLOOP:%.*]] = phi i32 [ [[IDX_NEXT_POSTLOOP:%.*]], [[IN_BOUNDS_POSTLOOP:%.*]] ], [ [[IDX_COPY]], [[POSTLOOP]] ]
547 ; CHECK-NEXT: [[IDX_NEXT_POSTLOOP]] = add i32 [[IDX_POSTLOOP]], 1
548 ; CHECK-NEXT: [[ABC_POSTLOOP:%.*]] = icmp ult i32 [[IDX_POSTLOOP]], [[BOUND]]
549 ; CHECK-NEXT: br i1 [[ABC_POSTLOOP]], label [[IN_BOUNDS_POSTLOOP]], label [[OUT_OF_BOUNDS_LOOPEXIT:%.*]], !prof !0
550 ; CHECK: in.bounds.postloop:
551 ; CHECK-NEXT: [[ADDR_POSTLOOP:%.*]] = getelementptr i32, i32* [[ARR]], i32 [[IDX_POSTLOOP]]
552 ; CHECK-NEXT: store i32 0, i32* [[ADDR_POSTLOOP]]
553 ; CHECK-NEXT: [[NEXT_POSTLOOP:%.*]] = icmp ult i32 [[IDX_NEXT_POSTLOOP]], [[N]]
554 ; CHECK-NEXT: br i1 [[NEXT_POSTLOOP]], label [[LOOP_POSTLOOP]], label [[EXIT_LOOPEXIT_LOOPEXIT:%.*]], !llvm.loop !9, !irce.loop.clone !6
557 %first.itr.check = icmp sgt i32 %n, 0
558 br i1 %first.itr.check, label %loop, label %exit
561 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
562 %idx.next = add i32 %idx, 1
563 %abc = icmp ult i32 %idx, %bound
564 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !0
567 %addr = getelementptr i32, i32* %arr, i32 %idx
568 store i32 0, i32* %addr
569 %next = icmp ult i32 %idx.next, %n
570 br i1 %next, label %loop, label %exit
578 !0 = !{!"branch_weights", i32 64, i32 4}