1 ; RUN: opt < %s -unroll-runtime-other-exit-predictable=false -loop-unroll -unroll-runtime=true -verify-dom-info -verify-loop-info -instcombine -S | FileCheck %s
2 ; RUN: opt < %s -unroll-runtime-other-exit-predictable=false -loop-unroll -unroll-runtime=true -verify-dom-info -unroll-runtime-multi-exit=false -verify-loop-info -S | FileCheck %s -check-prefix=NOUNROLL
4 ; this tests when unrolling multiple exit loop occurs by default (i.e. without specifying -unroll-runtime-multi-exit)
6 ; the second exit block is a deopt block. The loop has one exiting block other than the latch.
7 define i32 @test1(i32* nocapture %a, i64 %n) {
9 ; CHECK-LABEL: header.epil:
10 ; CHECK-NEXT: %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %latch.epil ], [ %indvars.iv.unr, %header.epil.preheader ]
11 ; CHECK-LABEL: otherexit.loopexit:
12 ; CHECK-NEXT: %sum.02.lcssa.ph = phi i32 [ %sum.02, %for.exiting_block ], [ %add, %for.exiting_block.1 ], [ %add.1, %for.exiting_block.2 ], [ %add.2, %for.exiting_block.3 ], [ %add.3, %for.exiting_block.4 ], [ %add.4, %for.exiting_block.5 ], [ %add.5, %for.exiting_block.6 ],
13 ; CHECK-NEXT: br label %otherexit
14 ; CHECK-LABEL: otherexit.loopexit3:
15 ; CHECK-NEXT: br label %otherexit
16 ; CHECK-LABEL: otherexit:
17 ; CHECK-NEXT: %sum.02.lcssa = phi i32 [ %sum.02.lcssa.ph, %otherexit.loopexit ], [ %sum.02.epil, %otherexit.loopexit3 ]
18 ; CHECK-NEXT: %rval = call i32 (...) @llvm.experimental.deoptimize.i32() [ "deopt"(i32 %sum.02.lcssa) ]
19 ; CHECK-NEXT: ret i32 %rval
20 ; CHECK-LABEL: latch.7:
21 ; CHECK: add i64 %indvars.iv, 8
26 ; NOUNROLL: otherexit:
27 ; NOUNROLL-NEXT: %sum.02.lcssa = phi i32 [ %sum.02, %for.exiting_block ]
28 ; NOUNROLL-NEXT: %rval = call i32 (...) @llvm.experimental.deoptimize.i32() [ "deopt"(i32 %sum.02.lcssa) ]
33 %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ]
34 %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ]
35 br label %for.exiting_block
38 %cmp = icmp eq i64 %n, 42
39 br i1 %cmp, label %otherexit, label %latch
42 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
43 %0 = load i32, i32* %arrayidx, align 4
44 %add = add nsw i32 %0, %sum.02
45 %indvars.iv.next = add i64 %indvars.iv, 1
46 %exitcond = icmp eq i64 %indvars.iv.next, %n
47 br i1 %exitcond, label %latchexit, label %header
49 latchexit: ; preds = %latch
50 %sum.0.lcssa = phi i32 [ %add, %latch ]
54 %rval = call i32(...) @llvm.experimental.deoptimize.i32() [ "deopt"(i32 %sum.02) ]
58 ; the exit block is not a deopt block.
59 define i32 @test2(i32* nocapture %a, i64 %n) {
63 ; CHECK-LABEL: otherexit:
64 ; CHECK-NEXT: ret i32 %sum.02
70 %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ]
71 %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ]
72 br label %for.exiting_block
75 %cmp = icmp eq i64 %n, 42
76 br i1 %cmp, label %otherexit, label %latch
79 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
80 %0 = load i32, i32* %arrayidx, align 4
81 %add = add nsw i32 %0, %sum.02
82 %indvars.iv.next = add i64 %indvars.iv, 1
83 %exitcond = icmp eq i64 %indvars.iv.next, %n
84 br i1 %exitcond, label %latchexit, label %header
86 latchexit: ; preds = %latch
87 %sum.0.lcssa = phi i32 [ %add, %latch ]
91 %rval = phi i32 [%sum.02, %for.exiting_block ]
94 declare i32 @llvm.experimental.deoptimize.i32(...)