1 ; RUN: opt < %s -loop-unroll -unroll-runtime=true -unroll-runtime-epilog=true -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -S | FileCheck %s -check-prefix=EPILOG-NO-IC
2 ; RUN: opt < %s -loop-unroll -unroll-runtime=true -unroll-runtime-epilog=true -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -instcombine -S | FileCheck %s -check-prefix=EPILOG
3 ; RUN: opt < %s -loop-unroll -unroll-runtime -unroll-count=2 -unroll-runtime-epilog=true -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -instcombine
4 ; RUN: opt < %s -loop-unroll -unroll-runtime=true -unroll-runtime-epilog=false -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -instcombine -S | FileCheck %s -check-prefix=PROLOG
5 ; RUN: opt < %s -loop-unroll -unroll-runtime -unroll-runtime-epilog=false -unroll-count=2 -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -instcombine
9 ; the third and fifth RUNs generate an epilog/prolog remainder block for all the test
10 ; cases below (it does not generate a loop).
12 ; test with three exiting and three exit blocks.
13 ; none of the exit blocks have successors
14 define void @test1(i64 %trip, i1 %cond) {
17 ; EPILOG-NEXT: [[TMP0:%.*]] = add i64 [[TRIP:%.*]], -1
18 ; EPILOG-NEXT: [[XTRAITER:%.*]] = and i64 [[TRIP]], 7
19 ; EPILOG-NEXT: [[TMP1:%.*]] = icmp ult i64 [[TMP0]], 7
20 ; EPILOG-NEXT: br i1 [[TMP1]], label %exit2.loopexit.unr-lcssa, label [[ENTRY_NEW:%.*]]
22 ; EPILOG-NEXT: [[UNROLL_ITER:%.*]] = sub i64 [[TRIP]], [[XTRAITER]]
23 ; EPILOG-NEXT: br label [[LOOP_HEADER:%.*]]
24 ; EPILOG: loop_latch.epil:
25 ; EPILOG-NEXT: %epil.iter.sub = add i64 %epil.iter, -1
26 ; EPILOG-NEXT: %epil.iter.cmp = icmp eq i64 %epil.iter.sub, 0
27 ; EPILOG-NEXT: br i1 %epil.iter.cmp, label %exit2.loopexit.epilog-lcssa, label %loop_header.epil
28 ; EPILOG: loop_latch.7:
29 ; EPILOG-NEXT: %niter.nsub.7 = add i64 %niter, -8
30 ; EPILOG-NEXT: %niter.ncmp.7 = icmp eq i64 %niter.nsub.7, 0
31 ; EPILOG-NEXT: br i1 %niter.ncmp.7, label %exit2.loopexit.unr-lcssa.loopexit, label %loop_header
35 ; PROLOG-NEXT: [[TMP0:%.*]] = add i64 [[TRIP:%.*]], -1
36 ; PROLOG-NEXT: [[XTRAITER:%.*]] = and i64 [[TRIP]], 7
37 ; PROLOG-NEXT: [[TMP1:%.*]] = icmp eq i64 [[XTRAITER]], 0
38 ; PROLOG-NEXT: br i1 [[TMP1]], label %loop_header.prol.loopexit, label %loop_header.prol.preheader
39 ; PROLOG: loop_header.prol:
40 ; PROLOG-NEXT: %iv.prol = phi i64 [ 0, %loop_header.prol.preheader ], [ %iv_next.prol, %loop_latch.prol ]
41 ; PROLOG-NEXT: %prol.iter = phi i64 [ [[XTRAITER]], %loop_header.prol.preheader ], [ %prol.iter.sub, %loop_latch.prol ]
42 ; PROLOG-NEXT: br i1 %cond, label %loop_latch.prol, label %loop_exiting_bb1.prol
43 ; PROLOG: loop_latch.prol:
44 ; PROLOG-NEXT: %iv_next.prol = add i64 %iv.prol, 1
45 ; PROLOG-NEXT: %prol.iter.sub = add i64 %prol.iter, -1
46 ; PROLOG-NEXT: %prol.iter.cmp = icmp eq i64 %prol.iter.sub, 0
47 ; PROLOG-NEXT: br i1 %prol.iter.cmp, label %loop_header.prol.loopexit.unr-lcssa, label %loop_header.prol
48 ; PROLOG: loop_latch.7:
49 ; PROLOG-NEXT: %iv_next.7 = add i64 %iv, 8
50 ; PROLOG-NEXT: %cmp.7 = icmp eq i64 %iv_next.7, %trip
51 ; PROLOG-NEXT: br i1 %cmp.7, label %exit2.loopexit.unr-lcssa, label %loop_header
56 %iv = phi i64 [ 0, %entry ], [ %iv_next, %loop_latch ]
57 br i1 %cond, label %loop_latch, label %loop_exiting_bb1
60 br i1 false, label %loop_exiting_bb2, label %exit1
63 br i1 false, label %loop_latch, label %exit3
69 %iv_next = add i64 %iv, 1
70 %cmp = icmp ne i64 %iv_next, %trip
71 br i1 %cmp, label %loop_header, label %exit2.loopexit
81 ; test with three exiting and two exit blocks.
82 ; The non-latch exit block has 2 unique predecessors.
83 ; There are 2 values passed to the exit blocks that are calculated at every iteration.
84 ; %sum.02 and %add. Both of these are incoming values for phi from every exiting
86 define i32 @test2(i32* nocapture %a, i64 %n) {
88 ; EPILOG: for.exit2.loopexit:
89 ; EPILOG-NEXT: %retval.ph = phi i32 [ 42, %for.exiting_block ], [ %sum.02, %header ], [ %add, %for.body ], [ 42, %for.exiting_block.1 ], [ %add.1, %for.body.1 ], [ 42, %for.exiting_block.2 ], [ %add.2, %for.body.2 ], [ 42, %for.exiting_block.3 ],
90 ; EPILOG-NEXT: br label %for.exit2
91 ; EPILOG: for.exit2.loopexit2:
92 ; EPILOG-NEXT: %retval.ph3 = phi i32 [ 42, %for.exiting_block.epil ], [ %sum.02.epil, %header.epil ]
93 ; EPILOG-NEXT: br label %for.exit2
95 ; EPILOG-NEXT: %retval = phi i32 [ %retval.ph, %for.exit2.loopexit ], [ %retval.ph3, %for.exit2.loopexit2 ]
96 ; EPILOG-NEXT: ret i32 %retval
97 ; EPILOG: %niter.nsub.7 = add i64 %niter, -8
100 ; PROLOG: for.exit2.loopexit:
101 ; PROLOG-NEXT: %retval.ph = phi i32 [ 42, %for.exiting_block ], [ %sum.02, %header ], [ %add, %for.body ], [ 42, %for.exiting_block.1 ], [ %add.1, %for.body.1 ], [ 42, %for.exiting_block.2 ], [ %add.2, %for.body.2 ], [ 42, %for.exiting_block.3 ],
102 ; PROLOG-NEXT: br label %for.exit2
103 ; PROLOG: for.exit2.loopexit1:
104 ; PROLOG-NEXT: %retval.ph2 = phi i32 [ 42, %for.exiting_block.prol ], [ %sum.02.prol, %header.prol ]
105 ; PROLOG-NEXT: br label %for.exit2
107 ; PROLOG-NEXT: %retval = phi i32 [ %retval.ph, %for.exit2.loopexit ], [ %retval.ph2, %for.exit2.loopexit1 ]
108 ; PROLOG-NEXT: ret i32 %retval
109 ; PROLOG: %indvars.iv.next.7 = add i64 %indvars.iv, 8
115 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
116 %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ]
117 br i1 false, label %for.exit2, label %for.exiting_block
120 %cmp = icmp eq i64 %n, 42
121 br i1 %cmp, label %for.exit2, label %for.body
124 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
125 %0 = load i32, i32* %arrayidx, align 4
126 %add = add nsw i32 %0, %sum.02
127 %indvars.iv.next = add i64 %indvars.iv, 1
128 %exitcond = icmp eq i64 %indvars.iv.next, %n
129 br i1 %exitcond, label %for.end, label %header
131 for.end: ; preds = %for.body
132 %sum.0.lcssa = phi i32 [ %add, %for.body ]
136 %retval = phi i32 [ %sum.02, %header ], [ 42, %for.exiting_block ]
140 ; test with two exiting and three exit blocks.
141 ; the non-latch exiting block has a switch.
142 define void @test3(i64 %trip, i64 %add) {
144 ; EPILOG-NEXT: entry:
145 ; EPILOG-NEXT: [[TMP0:%.*]] = add i64 [[TRIP:%.*]], -1
146 ; EPILOG-NEXT: [[XTRAITER:%.*]] = and i64 [[TRIP]], 7
147 ; EPILOG-NEXT: [[TMP1:%.*]] = icmp ult i64 [[TMP0]], 7
148 ; EPILOG-NEXT: br i1 [[TMP1]], label %exit2.loopexit.unr-lcssa, label [[ENTRY_NEW:%.*]]
150 ; EPILOG-NEXT: %unroll_iter = sub i64 [[TRIP]], [[XTRAITER]]
151 ; EPILOG-NEXT: br label [[LOOP_HEADER:%.*]]
152 ; EPILOG: loop_header:
153 ; EPILOG-NEXT: %sum = phi i64 [ 0, %entry.new ], [ %sum.next.7, %loop_latch.7 ]
154 ; EPILOG-NEXT: %niter = phi i64 [ %unroll_iter, %entry.new ], [ %niter.nsub.7, %loop_latch.7 ]
155 ; EPILOG: loop_exiting_bb1.7:
156 ; EPILOG-NEXT: switch i64 %sum.next.6, label %loop_latch.7
157 ; EPILOG: loop_latch.7:
158 ; EPILOG-NEXT: %sum.next.7 = add i64 %sum.next.6, %add
159 ; EPILOG-NEXT: %niter.nsub.7 = add i64 %niter, -8
160 ; EPILOG-NEXT: %niter.ncmp.7 = icmp eq i64 %niter.nsub.7, 0
161 ; EPILOG-NEXT: br i1 %niter.ncmp.7, label %exit2.loopexit.unr-lcssa.loopexit, label %loop_header
164 ; PROLOG-NEXT: entry:
165 ; PROLOG-NEXT: [[TMP0:%.*]] = add i64 [[TRIP:%.*]], -1
166 ; PROLOG-NEXT: [[XTRAITER:%.*]] = and i64 [[TRIP]], 7
167 ; PROLOG-NEXT: [[TMP1:%.*]] = icmp eq i64 [[XTRAITER]], 0
168 ; PROLOG-NEXT: br i1 [[TMP1]], label %loop_header.prol.loopexit, label %loop_header.prol.preheader
169 ; PROLOG: loop_header:
170 ; PROLOG-NEXT: %iv = phi i64 [ %iv.unr, %entry.new ], [ %iv_next.7, %loop_latch.7 ]
171 ; PROLOG-NEXT: %sum = phi i64 [ %sum.unr, %entry.new ], [ %sum.next.7, %loop_latch.7 ]
172 ; PROLOG: loop_exiting_bb1.7:
173 ; PROLOG-NEXT: switch i64 %sum.next.6, label %loop_latch.7
174 ; PROLOG: loop_latch.7:
175 ; PROLOG-NEXT: %iv_next.7 = add nuw nsw i64 %iv, 8
176 ; PROLOG-NEXT: %sum.next.7 = add i64 %sum.next.6, %add
177 ; PROLOG-NEXT: %cmp.7 = icmp eq i64 %iv_next.7, %trip
178 ; PROLOG-NEXT: br i1 %cmp.7, label %exit2.loopexit.unr-lcssa, label %loop_header
180 br label %loop_header
183 %iv = phi i64 [ 0, %entry ], [ %iv_next, %loop_latch ]
184 %sum = phi i64 [ 0, %entry ], [ %sum.next, %loop_latch ]
185 br i1 undef, label %loop_latch, label %loop_exiting_bb1
188 switch i64 %sum, label %loop_latch [
197 %iv_next = add nuw nsw i64 %iv, 1
198 %sum.next = add i64 %sum, %add
199 %cmp = icmp ne i64 %iv_next, %trip
200 br i1 %cmp, label %loop_header, label %exit2.loopexit
209 ; FIXME: Support multiple exiting blocks to the same latch exit block.
210 ; Three exiting blocks where header and latch exit to same LatchExit.
211 define i32 @hdr_latch_same_exit(i32* nocapture %a, i64 %n, i1 %cond) {
212 ; EPILOG: hdr_latch_same_exit(
216 ; PROLOG: hdr_latch_same_exit(
223 %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ]
224 %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ]
225 br i1 %cond, label %latchExit, label %for.exiting_block
228 %cmp = icmp eq i64 %n, 42
229 br i1 %cmp, label %for.exit2, label %latch
231 latch: ; preds = %latch, %entry
232 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
233 %0 = load i32, i32* %arrayidx, align 4
234 %add = add nsw i32 %0, %sum.02
235 %indvars.iv.next = add i64 %indvars.iv, 1
236 %exitcond = icmp eq i64 %indvars.iv.next, %n
237 br i1 %exitcond, label %latchExit, label %header
239 latchExit: ; preds = %latch, %entry
240 %result = phi i32 [ 0, %header ], [ %add, %latch ]
247 ; Two exiting blocks to latch where the exiting blocks are Latch and a
249 ; FIXME: We should unroll this loop.
250 define i32 @otherblock_latch_same_exit(i32* nocapture %a, i64 %n, i1 %cond) {
251 ; EPILOG: otherblock_latch_same_exit(
255 ; PROLOG: otherblock_latch_same_exit(
262 %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ]
263 %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ]
264 br i1 %cond, label %for.exit2, label %for.exiting_block
267 %cmp = icmp eq i64 %n, 42
268 br i1 %cmp, label %latchExit, label %latch
270 latch: ; preds = %latch, %entry
271 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
272 %0 = load i32, i32* %arrayidx, align 4
273 %add = add nsw i32 %0, %sum.02
274 %indvars.iv.next = add i64 %indvars.iv, 1
275 %exitcond = icmp eq i64 %indvars.iv.next, %n
276 br i1 %exitcond, label %latchExit, label %header
278 latchExit: ; preds = %latch, %entry
279 %result = phi i32 [ 2, %for.exiting_block ], [ %add, %latch ]
286 ; Two exiting blocks to latch where the exiting blocks are Latch and a
288 ; Same as above test except the incoming value for latch Phi is from the header
289 ; FIXME: We should be able to runtime unroll.
290 define i32 @otherblock_latch_same_exit2(i32* nocapture %a, i64 %n, i1 %cond) {
291 ; EPILOG: otherblock_latch_same_exit2(
295 ; PROLOG: otherblock_latch_same_exit2(
302 %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ]
303 %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ]
304 br i1 %cond, label %for.exit2, label %for.exiting_block
307 %cmp = icmp eq i64 %n, 42
308 br i1 %cmp, label %latchExit, label %latch
310 latch: ; preds = %latch, %entry
311 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
312 %0 = load i32, i32* %arrayidx, align 4
313 %add = add nsw i32 %0, %sum.02
314 %indvars.iv.next = add i64 %indvars.iv, 1
315 %exitcond = icmp eq i64 %indvars.iv.next, %n
316 br i1 %exitcond, label %latchExit, label %header
318 latchExit: ; preds = %latch, %entry
319 %result = phi i32 [ %sum.02, %for.exiting_block ], [ %add, %latch ]
326 ; Two exiting blocks to latch where the exiting blocks are Latch and a
328 ; Same as above test except the incoming value for cloned latch Phi is from the
330 ; FIXME: We should be able to runtime unroll.
331 define i32 @otherblock_latch_same_exit3(i32* nocapture %a, i64 %n, i1 %cond) {
332 ; EPILOG: otherblock_latch_same_exit3(
336 ; PROLOG: otherblock_latch_same_exit3(
343 %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ]
344 %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ]
345 br i1 %cond, label %for.exit2, label %for.exiting_block
348 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
349 %0 = load i32, i32* %arrayidx, align 4
350 %add = add nsw i32 %0, %sum.02
351 %cmp = icmp eq i64 %n, 42
352 br i1 %cmp, label %latchExit, label %latch
354 latch: ; preds = %latch, %entry
355 %indvars.iv.next = add i64 %indvars.iv, 1
356 %exitcond = icmp eq i64 %indvars.iv.next, %n
357 br i1 %exitcond, label %latchExit, label %header
359 latchExit: ; preds = %latch, %entry
360 %result = phi i32 [ %sum.02, %for.exiting_block ], [ %add, %latch ]
367 ; FIXME: Support multiple exiting blocks to the unique exit block (LatchExit).
368 ; Only 2 blocks in loop: header and latch where both exit to same LatchExit.
369 define void @unique_exit(i32 %arg) {
370 ; EPILOG: unique_exit(
374 ; PROLOG: unique_exit(
378 %tmp = icmp sgt i32 undef, %arg
379 br i1 %tmp, label %preheader, label %returnblock
381 preheader: ; preds = %entry
384 header: ; preds = %preheader, %latch
385 %tmp4 = phi i32 [ %inc, %latch ], [ %arg, %preheader ]
386 %inc = add nsw i32 %tmp4, 1
387 br i1 true, label %latchExit, label %latch
389 latch: ; preds = %header
390 %cmp = icmp slt i32 %inc, undef
391 br i1 %cmp, label %header, label %latchExit
393 latchExit: ; preds = %header, %latch
394 %tmp2.ph = phi i32 [ %tmp4, %header ], [ -1, %latch ]
395 br label %returnblock
397 returnblock: ; preds = %latchExit, %entry
398 %tmp2 = phi i32 [ -1, %entry ], [ %tmp2.ph, %latchExit ]
402 ; two exiting and two exit blocks.
403 ; the non-latch exiting block has duplicate edges to the non-latch exit block.
404 define i64 @test5(i64 %trip, i64 %add, i1 %cond) {
406 ; EPILOG: exit1.loopexit:
407 ; EPILOG-NEXT: %result.ph = phi i64 [ %ivy, %loop_exiting ], [ %ivy, %loop_exiting ], [ %ivy.1, %loop_exiting.1 ], [ %ivy.1, %loop_exiting.1 ], [ %ivy.2, %loop_exiting.2 ],
408 ; EPILOG-NEXT: br label %exit1
409 ; EPILOG: exit1.loopexit2:
410 ; EPILOG-NEXT: %ivy.epil = add i64 %iv.epil, %add
411 ; EPILOG-NEXT: br label %exit1
413 ; EPILOG-NEXT: %result = phi i64 [ %result.ph, %exit1.loopexit ], [ %ivy.epil, %exit1.loopexit2 ]
414 ; EPILOG-NEXT: ret i64 %result
415 ; EPILOG: loop_latch.7:
416 ; EPILOG: %niter.nsub.7 = add i64 %niter, -8
419 ; PROLOG: exit1.loopexit:
420 ; PROLOG-NEXT: %result.ph = phi i64 [ %ivy, %loop_exiting ], [ %ivy, %loop_exiting ], [ %ivy.1, %loop_exiting.1 ], [ %ivy.1, %loop_exiting.1 ], [ %ivy.2, %loop_exiting.2 ],
421 ; PROLOG-NEXT: br label %exit1
422 ; PROLOG: exit1.loopexit1:
423 ; PROLOG-NEXT: %ivy.prol = add i64 %iv.prol, %add
424 ; PROLOG-NEXT: br label %exit1
426 ; PROLOG-NEXT: %result = phi i64 [ %result.ph, %exit1.loopexit ], [ %ivy.prol, %exit1.loopexit1 ]
427 ; PROLOG-NEXT: ret i64 %result
428 ; PROLOG: loop_latch.7:
429 ; PROLOG: %iv_next.7 = add nuw nsw i64 %iv, 8
431 br label %loop_header
434 %iv = phi i64 [ 0, %entry ], [ %iv_next, %loop_latch ]
435 %sum = phi i64 [ 0, %entry ], [ %sum.next, %loop_latch ]
436 br i1 %cond, label %loop_latch, label %loop_exiting
439 %ivy = add i64 %iv, %add
440 switch i64 %sum, label %loop_latch [
446 %iv_next = add nuw nsw i64 %iv, 1
447 %sum.next = add i64 %sum, %add
448 %cmp = icmp ne i64 %iv_next, %trip
449 br i1 %cmp, label %loop_header, label %latchexit
452 %result = phi i64 [ %ivy, %loop_exiting ], [ %ivy, %loop_exiting ]
459 ; test when exit blocks have successors.
460 define i32 @test6(i32* nocapture %a, i64 %n, i1 %cond, i32 %x) {
462 ; EPILOG: for.exit2.loopexit:
463 ; EPILOG-NEXT: %retval.ph = phi i32 [ 42, %for.exiting_block ], [ %sum.02, %header ], [ %add, %latch ], [ 42, %for.exiting_block.1 ], [ %add.1, %latch.1 ], [ 42, %for.exiting_block.2 ], [ %add.2, %latch.2 ],
464 ; EPILOG-NEXT: br label %for.exit2
465 ; EPILOG: for.exit2.loopexit2:
466 ; EPILOG-NEXT: %retval.ph3 = phi i32 [ 42, %for.exiting_block.epil ], [ %sum.02.epil, %header.epil ]
467 ; EPILOG-NEXT: br label %for.exit2
469 ; EPILOG-NEXT: %retval = phi i32 [ %retval.ph, %for.exit2.loopexit ], [ %retval.ph3, %for.exit2.loopexit2 ]
470 ; EPILOG-NEXT: br i1 %cond, label %exit_true, label %exit_false
472 ; EPILOG: %niter.nsub.7 = add i64 %niter, -8
475 ; PROLOG: for.exit2.loopexit:
476 ; PROLOG-NEXT: %retval.ph = phi i32 [ 42, %for.exiting_block ], [ %sum.02, %header ], [ %add, %latch ], [ 42, %for.exiting_block.1 ], [ %add.1, %latch.1 ], [ 42, %for.exiting_block.2 ], [ %add.2, %latch.2 ],
477 ; PROLOG-NEXT: br label %for.exit2
478 ; PROLOG: for.exit2.loopexit1:
479 ; PROLOG-NEXT: %retval.ph2 = phi i32 [ 42, %for.exiting_block.prol ], [ %sum.02.prol, %header.prol ]
480 ; PROLOG-NEXT: br label %for.exit2
482 ; PROLOG-NEXT: %retval = phi i32 [ %retval.ph, %for.exit2.loopexit ], [ %retval.ph2, %for.exit2.loopexit1 ]
483 ; PROLOG-NEXT: br i1 %cond, label %exit_true, label %exit_false
485 ; PROLOG: %indvars.iv.next.7 = add i64 %indvars.iv, 8
490 %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ]
491 %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ]
492 br i1 false, label %for.exit2, label %for.exiting_block
495 %cmp = icmp eq i64 %n, 42
496 br i1 %cmp, label %for.exit2, label %latch
499 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
500 %load = load i32, i32* %arrayidx, align 4
501 %add = add nsw i32 %load, %sum.02
502 %indvars.iv.next = add i64 %indvars.iv, 1
503 %exitcond = icmp eq i64 %indvars.iv.next, %n
504 br i1 %exitcond, label %latch_exit, label %header
507 %sum.0.lcssa = phi i32 [ %add, %latch ]
511 %retval = phi i32 [ %sum.02, %header ], [ 42, %for.exiting_block ]
512 %addx = add i32 %retval, %x
513 br i1 %cond, label %exit_true, label %exit_false
522 ; test when value in exit block does not have VMap.
523 define i32 @test7(i32 %arg, i32 %arg1, i32 %arg2) {
524 ; EPILOG-NO-IC: test7(
525 ; EPILOG-NO-IC: loopexit1.loopexit:
526 ; EPILOG-NO-IC-NEXT: %sext3.ph = phi i32 [ %shft, %header ], [ %shft, %latch ], [ %shft, %latch.1 ], [ %shft, %latch.2 ], [ %shft, %latch.3 ], [ %shft, %latch.4 ], [ %shft, %latch.5 ], [ %shft, %latch.6 ]
527 ; EPILOG-NO-IC-NEXT: br label %loopexit1
528 ; EPILOG-NO-IC: loopexit1.loopexit1:
529 ; EPILOG-NO-IC-NEXT: %sext3.ph2 = phi i32 [ %shft, %header.epil ]
530 ; EPILOG-NO-IC-NEXT: br label %loopexit1
531 ; EPILOG-NO-IC: loopexit1:
532 ; EPILOG-NO-IC-NEXT: %sext3 = phi i32 [ %sext3.ph, %loopexit1.loopexit ], [ %sext3.ph2, %loopexit1.loopexit1 ]
534 %tmp = icmp slt i32 undef, 2
535 %sext = sext i32 undef to i64
536 %shft = ashr exact i32 %arg, 16
537 br i1 %tmp, label %loopexit2, label %preheader
539 preheader: ; preds = %bb2
542 header: ; preds = %latch, %preheader
543 %tmp6 = phi i64 [ 1, %preheader ], [ %add, %latch ]
544 br i1 false, label %loopexit1, label %latch
546 latch: ; preds = %header
547 %add = add nuw nsw i64 %tmp6, 1
548 %tmp9 = icmp slt i64 %add, %sext
549 br i1 %tmp9, label %header, label %latchexit
551 latchexit: ; preds = %latch
554 loopexit2: ; preds = %bb2
557 loopexit1: ; preds = %header
558 %sext3 = phi i32 [ %shft, %header ]
562 ; Nested loop and inner loop is unrolled
563 ; FIXME: we cannot unroll with epilog remainder currently, because
564 ; the outer loop does not contain the epilog preheader and epilog exit (while
565 ; infact it should). This causes us to choke up on LCSSA form being incorrect in
566 ; outer loop. However, the exit block where LCSSA fails, is infact still within
567 ; the outer loop. For now, we just bail out in presence of outer loop and epilog
569 ; The outer loop header is the preheader for the inner loop and the inner header
570 ; branches back to the outer loop.
571 define void @test8() {
577 ; PROLOG-NEXT: phi i64 [ 3, %bb ], [ 0, %outerloop.loopexit ]
578 ; PROLOG: %lcmp.mod = icmp eq i64
579 ; PROLOG-NEXT: br i1 %lcmp.mod, label %innerH.prol.loopexit, label %innerH.prol.preheader
581 ; PROLOG-NEXT: %tmp4.7 = add nuw nsw i64 %tmp3, 8
582 ; PROLOG-NEXT: br i1 false, label %outerloop.loopexit.loopexit, label %latch.7
584 ; PROLOG-NEXT: %tmp6.7 = icmp ult i64 %tmp4.7, 100
585 ; PROLOG-NEXT: br i1 %tmp6.7, label %innerH, label %exit.unr-lcssa
589 outerloop: ; preds = %innerH, %bb
590 %tmp = phi i64 [ 3, %bb ], [ 0, %innerH ]
593 innerH: ; preds = %latch, %outerloop
594 %tmp3 = phi i64 [ %tmp4, %latch ], [ %tmp, %outerloop ]
595 %tmp4 = add nuw nsw i64 %tmp3, 1
596 br i1 false, label %outerloop, label %latch
598 latch: ; preds = %innerH
599 %tmp6 = icmp ult i64 %tmp4, 100
600 br i1 %tmp6, label %innerH, label %exit
602 exit: ; preds = %latch
606 declare i8 addrspace(1)* @foo(i32)
607 ; inner loop prolog unrolled
608 ; a value from outer loop is used in exit block of inner loop.
609 ; Don't create VMap entries for such values (%trip).
610 define i8 addrspace(1)* @test9(i8* nocapture readonly %arg, i32 %n) {
612 ; PROLOG: header.prol:
613 ; PROLOG-NEXT: %phi.prol = phi i64 [ 0, %header.prol.preheader ], [ %iv.next.prol, %latch.prol ]
614 ; PROLOG: latch.prol:
616 ; PROLOG: br i1 %prol.iter.cmp, label %header.prol.loopexit.unr-lcssa, label %header.prol
618 br label %outerloopHdr
620 outerloopHdr: ; preds = %outerLatch, %bb
621 %trip = add i32 %n, -1
622 %outercnd = icmp slt i32 0, %trip
623 br i1 %outercnd, label %preheader, label %outerLatch
625 preheader: ; preds = %outerloopHdr
626 %tmp4 = zext i32 0 to i64
629 header: ; preds = %latch, %preheader
630 %phi = phi i64 [ %tmp4, %preheader ], [ %iv.next, %latch ]
631 %tmp7 = trunc i64 %phi to i32
632 br i1 true, label %latch, label %innerexit
634 innerexit: ; preds = %header
635 %tmp9 = call i8 addrspace(1)* @foo(i32 %trip)
636 ret i8 addrspace(1)* %tmp9
638 latch: ; preds = %header
639 %tmp11 = add nsw i32 %tmp7, 1
640 %innercnd = icmp slt i32 %tmp11, %trip
641 %iv.next = add nuw nsw i64 %phi, 1
642 br i1 %innercnd, label %header, label %outerLatch
644 outerLatch: ; preds = %latch, %outerloopHdr
645 br label %outerloopHdr