1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -loop-unroll -S %s | FileCheck %s
6 define void @peel_unreachable_exit_and_latch_exit(i32* %ptr, i32 %N, i32 %x) {
7 ; CHECK-LABEL: @peel_unreachable_exit_and_latch_exit(
9 ; CHECK-NEXT: br label [[LOOP_HEADER_PEEL_BEGIN:%.*]]
10 ; CHECK: loop.header.peel.begin:
11 ; CHECK-NEXT: br label [[LOOP_HEADER_PEEL:%.*]]
12 ; CHECK: loop.header.peel:
13 ; CHECK-NEXT: [[C_PEEL:%.*]] = icmp ult i32 1, 2
14 ; CHECK-NEXT: br i1 [[C_PEEL]], label [[THEN_PEEL:%.*]], label [[ELSE_PEEL:%.*]]
16 ; CHECK-NEXT: [[C_2_PEEL:%.*]] = icmp eq i32 1, [[X:%.*]]
17 ; CHECK-NEXT: br i1 [[C_2_PEEL]], label [[UNREACHABLE_EXIT:%.*]], label [[LOOP_LATCH_PEEL:%.*]]
19 ; CHECK-NEXT: br label [[LOOP_LATCH_PEEL]]
20 ; CHECK: loop.latch.peel:
21 ; CHECK-NEXT: [[M_PEEL:%.*]] = phi i32 [ 0, [[THEN_PEEL]] ], [ [[X]], [[ELSE_PEEL]] ]
22 ; CHECK-NEXT: [[GEP_PEEL:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 1
23 ; CHECK-NEXT: store i32 [[M_PEEL]], i32* [[GEP_PEEL]], align 4
24 ; CHECK-NEXT: [[IV_NEXT_PEEL:%.*]] = add nuw nsw i32 1, 1
25 ; CHECK-NEXT: [[C_3_PEEL:%.*]] = icmp ult i32 1, 1000
26 ; CHECK-NEXT: br i1 [[C_3_PEEL]], label [[LOOP_HEADER_PEEL_NEXT:%.*]], label [[EXIT:%.*]]
27 ; CHECK: loop.header.peel.next:
28 ; CHECK-NEXT: br label [[LOOP_HEADER_PEEL_NEXT1:%.*]]
29 ; CHECK: loop.header.peel.next1:
30 ; CHECK-NEXT: br label [[ENTRY_PEEL_NEWPH:%.*]]
31 ; CHECK: entry.peel.newph:
32 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
34 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT_PEEL]], [[ENTRY_PEEL_NEWPH]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
35 ; CHECK-NEXT: br i1 false, label [[THEN:%.*]], label [[ELSE:%.*]]
37 ; CHECK-NEXT: br label [[LOOP_LATCH]]
39 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i32 [[IV]], [[X]]
40 ; CHECK-NEXT: br i1 [[C_2]], label [[UNREACHABLE_EXIT_LOOPEXIT:%.*]], label [[LOOP_LATCH]]
42 ; CHECK-NEXT: [[M:%.*]] = phi i32 [ 0, [[THEN]] ], [ [[X]], [[ELSE]] ]
43 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR]], i32 [[IV]]
44 ; CHECK-NEXT: store i32 [[M]], i32* [[GEP]], align 4
45 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
46 ; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
47 ; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP0:![0-9]+]]
48 ; CHECK: exit.loopexit:
49 ; CHECK-NEXT: br label [[EXIT]]
51 ; CHECK-NEXT: ret void
52 ; CHECK: unreachable.exit.loopexit:
53 ; CHECK-NEXT: br label [[UNREACHABLE_EXIT]]
54 ; CHECK: unreachable.exit:
55 ; CHECK-NEXT: call void @foo()
56 ; CHECK-NEXT: unreachable
62 %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
63 %c = icmp ult i32 %iv, 2
64 br i1 %c, label %then, label %else
70 %c.2 = icmp eq i32 %iv, %x
71 br i1 %c.2, label %unreachable.exit, label %loop.latch
74 %m = phi i32 [ 0, %then ], [ %x, %else ]
75 %gep = getelementptr i32, i32* %ptr, i32 %iv
76 store i32 %m, i32* %gep
77 %iv.next = add nuw nsw i32 %iv, 1
78 %c.3 = icmp ult i32 %iv, 1000
79 br i1 %c.3, label %loop.header, label %exit
89 define void @peel_unreachable_exit_and_header_exit(i32* %ptr, i32 %N, i32 %x) {
90 ; CHECK-LABEL: @peel_unreachable_exit_and_header_exit(
92 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
94 ; CHECK-NEXT: br i1 true, label [[EXIT:%.*]], label [[ELSE:%.*]]
96 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i32 1, [[X:%.*]]
97 ; CHECK-NEXT: br i1 [[C_2]], label [[UNREACHABLE_EXIT:%.*]], label [[LOOP_LATCH:%.*]]
99 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 1
100 ; CHECK-NEXT: store i32 [[X]], i32* [[GEP]], align 4
101 ; CHECK-NEXT: unreachable
103 ; CHECK-NEXT: ret void
104 ; CHECK: unreachable.exit:
105 ; CHECK-NEXT: call void @foo()
106 ; CHECK-NEXT: unreachable
109 br label %loop.header
112 %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
113 %c = icmp ult i32 %iv, 1000
114 br i1 %c, label %exit, label %else
117 %c.2 = icmp eq i32 %iv, %x
118 br i1 %c.2, label %unreachable.exit, label %loop.latch
121 %gep = getelementptr i32, i32* %ptr, i32 %iv
122 store i32 %x, i32* %gep
123 %iv.next = add nuw nsw i32 %iv, 1
124 br label %loop.header
134 define void @peel_unreachable_and_multiple_reachable_exits(i32* %ptr, i32 %N, i32 %x) {
135 ; CHECK-LABEL: @peel_unreachable_and_multiple_reachable_exits(
137 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
138 ; CHECK: loop.header:
139 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
140 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[IV]], 2
141 ; CHECK-NEXT: br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]]
143 ; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i32 [[IV]], [[X:%.*]]
144 ; CHECK-NEXT: br i1 [[C_2]], label [[EXIT:%.*]], label [[LOOP_LATCH]]
146 ; CHECK-NEXT: [[C_3:%.*]] = icmp eq i32 [[IV]], [[X]]
147 ; CHECK-NEXT: br i1 [[C_3]], label [[UNREACHABLE_EXIT:%.*]], label [[LOOP_LATCH]]
149 ; CHECK-NEXT: [[M:%.*]] = phi i32 [ 0, [[THEN]] ], [ [[X]], [[ELSE]] ]
150 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
151 ; CHECK-NEXT: store i32 [[M]], i32* [[GEP]], align 4
152 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
153 ; CHECK-NEXT: [[C_4:%.*]] = icmp ult i32 [[IV]], 1000
154 ; CHECK-NEXT: br i1 [[C_4]], label [[LOOP_HEADER]], label [[EXIT]]
156 ; CHECK-NEXT: ret void
157 ; CHECK: unreachable.exit:
158 ; CHECK-NEXT: call void @foo()
159 ; CHECK-NEXT: unreachable
162 br label %loop.header
165 %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
166 %c = icmp ult i32 %iv, 2
167 br i1 %c, label %then, label %else
170 %c.2 = icmp sgt i32 %iv, %x
171 br i1 %c.2, label %exit, label %loop.latch
174 %c.3 = icmp eq i32 %iv, %x
175 br i1 %c.3, label %unreachable.exit, label %loop.latch
178 %m = phi i32 [ 0, %then ], [ %x, %else ]
179 %gep = getelementptr i32, i32* %ptr, i32 %iv
180 store i32 %m, i32* %gep
181 %iv.next = add nuw nsw i32 %iv, 1
182 %c.4 = icmp ult i32 %iv, 1000
183 br i1 %c.4, label %loop.header, label %exit
193 define void @peel_exits_to_blocks_branch_to_unreachable_block(i32* %ptr, i32 %N, i32 %x, i1 %c.1) {
194 ; CHECK-LABEL: @peel_exits_to_blocks_branch_to_unreachable_block(
196 ; CHECK-NEXT: br label [[LOOP_HEADER_PEEL_BEGIN:%.*]]
197 ; CHECK: loop.header.peel.begin:
198 ; CHECK-NEXT: br label [[LOOP_HEADER_PEEL:%.*]]
199 ; CHECK: loop.header.peel:
200 ; CHECK-NEXT: [[C_PEEL:%.*]] = icmp ult i32 1, 2
201 ; CHECK-NEXT: br i1 [[C_PEEL]], label [[THEN_PEEL:%.*]], label [[ELSE_PEEL:%.*]]
203 ; CHECK-NEXT: [[C_2_PEEL:%.*]] = icmp eq i32 1, [[X:%.*]]
204 ; CHECK-NEXT: br i1 [[C_2_PEEL]], label [[EXIT_2:%.*]], label [[LOOP_LATCH_PEEL:%.*]]
206 ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[EXIT_1:%.*]], label [[LOOP_LATCH_PEEL]]
207 ; CHECK: loop.latch.peel:
208 ; CHECK-NEXT: [[M_PEEL:%.*]] = phi i32 [ 0, [[THEN_PEEL]] ], [ [[X]], [[ELSE_PEEL]] ]
209 ; CHECK-NEXT: [[GEP_PEEL:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 1
210 ; CHECK-NEXT: store i32 [[M_PEEL]], i32* [[GEP_PEEL]], align 4
211 ; CHECK-NEXT: [[IV_NEXT_PEEL:%.*]] = add nuw nsw i32 1, 1
212 ; CHECK-NEXT: [[C_3_PEEL:%.*]] = icmp ult i32 1, 1000
213 ; CHECK-NEXT: br i1 [[C_3_PEEL]], label [[LOOP_HEADER_PEEL_NEXT:%.*]], label [[EXIT:%.*]]
214 ; CHECK: loop.header.peel.next:
215 ; CHECK-NEXT: br label [[LOOP_HEADER_PEEL_NEXT1:%.*]]
216 ; CHECK: loop.header.peel.next1:
217 ; CHECK-NEXT: br label [[ENTRY_PEEL_NEWPH:%.*]]
218 ; CHECK: entry.peel.newph:
219 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
220 ; CHECK: loop.header:
221 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT_PEEL]], [[ENTRY_PEEL_NEWPH]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
222 ; CHECK-NEXT: br i1 false, label [[THEN:%.*]], label [[ELSE:%.*]]
224 ; CHECK-NEXT: br i1 [[C_1]], label [[EXIT_1_LOOPEXIT:%.*]], label [[LOOP_LATCH]]
226 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i32 [[IV]], [[X]]
227 ; CHECK-NEXT: br i1 [[C_2]], label [[EXIT_2_LOOPEXIT:%.*]], label [[LOOP_LATCH]]
229 ; CHECK-NEXT: [[M:%.*]] = phi i32 [ 0, [[THEN]] ], [ [[X]], [[ELSE]] ]
230 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR]], i32 [[IV]]
231 ; CHECK-NEXT: store i32 [[M]], i32* [[GEP]], align 4
232 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
233 ; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV]], 1000
234 ; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP2:![0-9]+]]
235 ; CHECK: exit.loopexit:
236 ; CHECK-NEXT: br label [[EXIT]]
238 ; CHECK-NEXT: ret void
239 ; CHECK: exit.1.loopexit:
240 ; CHECK-NEXT: br label [[EXIT_1]]
242 ; CHECK-NEXT: call void @foo()
243 ; CHECK-NEXT: br label [[UNREACHABLE_TERM:%.*]]
244 ; CHECK: exit.2.loopexit:
245 ; CHECK-NEXT: br label [[EXIT_2]]
247 ; CHECK-NEXT: call void @bar()
248 ; CHECK-NEXT: br label [[UNREACHABLE_TERM]]
249 ; CHECK: unreachable.term:
250 ; CHECK-NEXT: call void @baz()
251 ; CHECK-NEXT: unreachable
254 br label %loop.header
257 %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
258 %c = icmp ult i32 %iv, 2
259 br i1 %c, label %then, label %else
262 br i1 %c.1, label %exit.1, label %loop.latch
265 %c.2 = icmp eq i32 %iv, %x
266 br i1 %c.2, label %exit.2, label %loop.latch
269 %m = phi i32 [ 0, %then ], [ %x, %else ]
270 %gep = getelementptr i32, i32* %ptr, i32 %iv
271 store i32 %m, i32* %gep
272 %iv.next = add nuw nsw i32 %iv, 1
273 %c.3 = icmp ult i32 %iv, 1000
274 br i1 %c.3, label %loop.header, label %exit
281 br label %unreachable.term
285 br label %unreachable.term
292 define void @peel_exits_to_blocks_branch_to_unreachable_block_with_invariant_load(i32* %ptr, i32 %N, i32 %x, i1 %c.1, i32 %y, i32* %size_ptr) {
293 ; CHECK-LABEL: @peel_exits_to_blocks_branch_to_unreachable_block_with_invariant_load(
295 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
296 ; CHECK: loop.header:
297 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
298 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[IV]], [[Y:%.*]]
299 ; CHECK-NEXT: br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]]
301 ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[EXIT_1:%.*]], label [[LOOP_LATCH]]
303 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i32 [[IV]], [[X:%.*]]
304 ; CHECK-NEXT: br i1 [[C_2]], label [[EXIT_2:%.*]], label [[LOOP_LATCH]]
306 ; CHECK-NEXT: [[M:%.*]] = phi i32 [ 0, [[THEN]] ], [ [[X]], [[ELSE]] ]
307 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
308 ; CHECK-NEXT: store i32 [[M]], i32* [[GEP]], align 4
309 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
310 ; CHECK-NEXT: [[SIZE:%.*]] = load i32, i32* [[SIZE_PTR:%.*]], align 4
311 ; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV_NEXT]], [[SIZE]]
312 ; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
314 ; CHECK-NEXT: ret void
316 ; CHECK-NEXT: call void @foo()
317 ; CHECK-NEXT: br label [[UNREACHABLE_TERM:%.*]]
319 ; CHECK-NEXT: call void @bar()
320 ; CHECK-NEXT: br label [[UNREACHABLE_TERM]]
321 ; CHECK: unreachable.term:
322 ; CHECK-NEXT: call void @baz()
323 ; CHECK-NEXT: unreachable
326 br label %loop.header
329 %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
330 %c = icmp ult i32 %iv, %y
331 br i1 %c, label %then, label %else
334 br i1 %c.1, label %exit.1, label %loop.latch
337 %c.2 = icmp eq i32 %iv, %x
338 br i1 %c.2, label %exit.2, label %loop.latch
341 %m = phi i32 [ 0, %then ], [ %x, %else ]
342 %gep = getelementptr i32, i32* %ptr, i32 %iv
343 store i32 %m, i32* %gep
344 %iv.next = add nuw nsw i32 %iv, 1
345 %size = load i32, i32* %size_ptr, align 4
346 %c.3 = icmp ult i32 %iv.next, %size
347 br i1 %c.3, label %loop.header, label %exit
354 br label %unreachable.term
358 br label %unreachable.term
365 define void @peel_exits_to_blocks_branch_to_unreachable_block_with_profile(i32* %ptr, i32 %N, i32 %x, i1 %c.1) !prof !0 {
366 ; CHECK-LABEL: @peel_exits_to_blocks_branch_to_unreachable_block_with_profile(
368 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
369 ; CHECK: loop.header:
370 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
371 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[IV]], [[N:%.*]]
372 ; CHECK-NEXT: br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]], !prof [[PROF3:![0-9]+]]
374 ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[EXIT_1:%.*]], label [[LOOP_LATCH]]
376 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i32 [[IV]], [[X:%.*]]
377 ; CHECK-NEXT: br i1 [[C_2]], label [[EXIT_2:%.*]], label [[LOOP_LATCH]]
379 ; CHECK-NEXT: [[M:%.*]] = phi i32 [ 0, [[THEN]] ], [ [[X]], [[ELSE]] ]
380 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
381 ; CHECK-NEXT: store i32 [[M]], i32* [[GEP]], align 4
382 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
383 ; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[IV_NEXT]], [[N]]
384 ; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]], !prof [[PROF3]]
386 ; CHECK-NEXT: ret void
388 ; CHECK-NEXT: call void @foo()
389 ; CHECK-NEXT: br label [[UNREACHABLE_TERM:%.*]]
391 ; CHECK-NEXT: call void @bar()
392 ; CHECK-NEXT: br label [[UNREACHABLE_TERM]]
393 ; CHECK: unreachable.term:
394 ; CHECK-NEXT: call void @baz()
395 ; CHECK-NEXT: unreachable
398 br label %loop.header
401 %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
402 %c = icmp ult i32 %iv, %N
403 br i1 %c, label %then, label %else, !prof !1
406 br i1 %c.1, label %exit.1, label %loop.latch
409 %c.2 = icmp eq i32 %iv, %x
410 br i1 %c.2, label %exit.2, label %loop.latch
413 %m = phi i32 [ 0, %then ], [ %x, %else ]
414 %gep = getelementptr i32, i32* %ptr, i32 %iv
415 store i32 %m, i32* %gep
416 %iv.next = add nuw nsw i32 %iv, 1
417 %c.3 = icmp ult i32 %iv.next, %N
418 br i1 %c.3, label %loop.header, label %exit, !prof !2
425 br label %unreachable.term
429 br label %unreachable.term
439 !0 = !{!"function_entry_count", i64 32768}
440 !1 = !{!"branch_weights", i32 0, i32 1}
441 !2 = !{!"branch_weights", i32 0, i32 1}