Serguei Katkov | 3ed93b4 | 2019-07-15 08:26:45 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -S -debug-only=loop-unroll -loop-unroll -unroll-runtime -unroll-peel-multi-deopt-exit 2>&1 | FileCheck %s |
| 2 | ; RUN: opt < %s -S -debug-only=loop-unroll -unroll-peel-multi-deopt-exit -passes='require<profile-summary>,function(require<opt-remark-emit>,unroll)' 2>&1 | FileCheck %s |
| 3 | |
| 4 | ; Make sure we use the profile information correctly to peel-off 3 iterations |
| 5 | ; from the loop, and update the branch weights for the peeled loop properly. |
| 6 | |
| 7 | ; CHECK: Loop Unroll: F[basic] |
| 8 | ; CHECK: PEELING loop %for.body with iteration count 3! |
| 9 | |
| 10 | ; CHECK-LABEL: @basic |
| 11 | ; CHECK: br i1 %{{.*}}, label %[[NEXT0:.*]], label %for.cond.for.end_crit_edge, !prof !16 |
| 12 | ; CHECK: [[NEXT0]]: |
| 13 | ; CHECK: br i1 %{{.*}}, label %[[NEXT1:.*]], label %for.cond.for.end_crit_edge, !prof !17 |
| 14 | ; CHECK: [[NEXT1]]: |
| 15 | ; CHECK: br i1 %{{.*}}, label %[[NEXT2:.*]], label %for.cond.for.end_crit_edge, !prof !18 |
| 16 | ; CHECK: [[NEXT2]]: |
| 17 | ; CHECK: br i1 %{{.*}}, label %for.body, label %{{.*}}, !prof !19 |
| 18 | |
| 19 | define i32 @basic(i32* %p, i32 %k, i1 %c) #0 !prof !15 { |
| 20 | entry: |
| 21 | %cmp3 = icmp slt i32 0, %k |
| 22 | br i1 %cmp3, label %for.body.lr.ph, label %for.end |
| 23 | |
| 24 | for.body.lr.ph: ; preds = %entry |
| 25 | br label %for.body |
| 26 | |
| 27 | for.body: ; preds = %for.body.lr.ph, %for.body |
| 28 | %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %continue ] |
| 29 | %p.addr.04 = phi i32* [ %p, %for.body.lr.ph ], [ %incdec.ptr, %continue ] |
| 30 | %incdec.ptr = getelementptr inbounds i32, i32* %p.addr.04, i32 1 |
| 31 | store i32 %i.05, i32* %p.addr.04, align 4 |
| 32 | %inc = add nsw i32 %i.05, 1 |
| 33 | %cmp = icmp slt i32 %inc, %k |
| 34 | br i1 %c, label %continue, label %side_exit, !prof !17 |
| 35 | |
| 36 | continue: |
| 37 | br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge, !prof !16 |
| 38 | |
| 39 | for.cond.for.end_crit_edge: ; preds = %for.body |
| 40 | br label %for.end |
| 41 | |
| 42 | for.end: ; preds = %for.cond.for.end_crit_edge, %entry |
| 43 | %res = phi i32 [ 0, %entry ], [ %inc, %for.cond.for.end_crit_edge ] |
| 44 | ret i32 %res |
| 45 | |
| 46 | side_exit: |
| 47 | %rval = call i32(...) @llvm.experimental.deoptimize.i32() [ "deopt"(i32 %inc) ] |
| 48 | ret i32 %rval |
| 49 | } |
| 50 | |
| 51 | declare i32 @llvm.experimental.deoptimize.i32(...) |
| 52 | |
| 53 | attributes #0 = { nounwind } |
| 54 | attributes #1 = { nounwind optsize } |
| 55 | |
| 56 | !llvm.module.flags = !{!1} |
| 57 | |
| 58 | !1 = !{i32 1, !"ProfileSummary", !2} |
| 59 | !2 = !{!3, !4, !5, !6, !7, !8, !9, !10} |
| 60 | !3 = !{!"ProfileFormat", !"InstrProf"} |
| 61 | !4 = !{!"TotalCount", i64 10} |
| 62 | !5 = !{!"MaxCount", i64 3} |
| 63 | !6 = !{!"MaxInternalCount", i64 1} |
| 64 | !7 = !{!"MaxFunctionCount", i64 3} |
| 65 | !8 = !{!"NumCounts", i64 2} |
| 66 | !9 = !{!"NumFunctions", i64 2} |
| 67 | !10 = !{!"DetailedSummary", !11} |
| 68 | !11 = !{!12, !13, !14} |
| 69 | !12 = !{i32 10000, i64 3, i32 2} |
| 70 | !13 = !{i32 999000, i64 1, i32 10} |
| 71 | !14 = !{i32 999999, i64 1, i32 10} |
| 72 | !15 = !{!"function_entry_count", i64 1} |
| 73 | !16 = !{!"branch_weights", i32 3001, i32 1001} |
| 74 | !17 = !{!"branch_weights", i32 1, i32 0} |
| 75 | |
| 76 | ;CHECK: !16 = !{!"branch_weights", i32 900, i32 101} |
| 77 | ;CHECK: !17 = !{!"branch_weights", i32 540, i32 360} |
| 78 | ;CHECK: !18 = !{!"branch_weights", i32 162, i32 378} |
| 79 | ;CHECK: !19 = !{!"branch_weights", i32 1399, i32 162} |
| 80 | |