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