Anna Thomas | f34537d | 2017-09-15 15:56:05 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -loop-unroll -unroll-runtime=true -verify-dom-info -verify-loop-info -instcombine -S | FileCheck %s |
| 2 | ; RUN: opt < %s -loop-unroll -unroll-runtime=true -verify-dom-info -unroll-runtime-multi-exit=false -verify-loop-info -S | FileCheck %s -check-prefix=NOUNROLL |
| 3 | |
| 4 | ; this tests when unrolling multiple exit loop occurs by default (i.e. without specifying -unroll-runtime-multi-exit) |
| 5 | |
| 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) { |
| 8 | ; CHECK-LABEL: test1( |
| 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 |
| 22 | |
| 23 | ; NOUNROLL: test1( |
| 24 | ; NOUNROLL-NOT: .epil |
| 25 | ; NOUNROLL-NOT: .prol |
| 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) ] |
| 29 | entry: |
| 30 | br label %header |
| 31 | |
| 32 | header: |
| 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 |
| 36 | |
| 37 | for.exiting_block: |
| 38 | %cmp = icmp eq i64 %n, 42 |
| 39 | br i1 %cmp, label %otherexit, label %latch |
| 40 | |
| 41 | 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 |
| 48 | |
| 49 | latchexit: ; preds = %latch |
| 50 | %sum.0.lcssa = phi i32 [ %add, %latch ] |
| 51 | ret i32 %sum.0.lcssa |
| 52 | |
| 53 | otherexit: |
| 54 | %rval = call i32(...) @llvm.experimental.deoptimize.i32() [ "deopt"(i32 %sum.02) ] |
| 55 | ret i32 %rval |
| 56 | } |
| 57 | |
| 58 | ; the exit block is not a deopt block. |
| 59 | define i32 @test2(i32* nocapture %a, i64 %n) { |
| 60 | ; CHECK-LABEL: test2( |
| 61 | ; CHECK-NOT: .epil |
| 62 | ; CHECK-NOT: .prol |
| 63 | ; CHECK-LABEL: otherexit: |
| 64 | ; CHECK-NEXT: ret i32 %sum.02 |
| 65 | |
| 66 | entry: |
| 67 | br label %header |
| 68 | |
| 69 | header: |
| 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 |
| 73 | |
| 74 | for.exiting_block: |
| 75 | %cmp = icmp eq i64 %n, 42 |
| 76 | br i1 %cmp, label %otherexit, label %latch |
| 77 | |
| 78 | 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 |
| 85 | |
| 86 | latchexit: ; preds = %latch |
| 87 | %sum.0.lcssa = phi i32 [ %add, %latch ] |
| 88 | ret i32 %sum.0.lcssa |
| 89 | |
| 90 | otherexit: |
| 91 | %rval = phi i32 [%sum.02, %for.exiting_block ] |
| 92 | ret i32 %rval |
| 93 | } |
| 94 | declare i32 @llvm.experimental.deoptimize.i32(...) |