blob: 27e54f9ac7590e78f1f0264d0d36074a0b78b3bb [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.
Serguei Katkovc6c31da2019-07-22 05:15:34 +00007; All side exits to deopt does not change weigths.
Serguei Katkov3ed93b42019-07-15 08:26:45 +00008
9; CHECK: Loop Unroll: F[basic]
10; CHECK: PEELING loop %for.body with iteration count 3!
11
12; CHECK-LABEL: @basic
Serguei Katkovc6c31da2019-07-22 05:15:34 +000013; CHECK: br i1 %c, label %{{.*}}, label %side_exit, !prof !15
Serguei Katkov3ed93b42019-07-15 08:26:45 +000014; CHECK: br i1 %{{.*}}, label %[[NEXT0:.*]], label %for.cond.for.end_crit_edge, !prof !16
15; CHECK: [[NEXT0]]:
Serguei Katkovc6c31da2019-07-22 05:15:34 +000016; CHECK: br i1 %c, label %{{.*}}, label %side_exit, !prof !15
Serguei Katkov3ed93b42019-07-15 08:26:45 +000017; CHECK: br i1 %{{.*}}, label %[[NEXT1:.*]], label %for.cond.for.end_crit_edge, !prof !17
18; CHECK: [[NEXT1]]:
Serguei Katkovc6c31da2019-07-22 05:15:34 +000019; CHECK: br i1 %c, label %{{.*}}, label %side_exit, !prof !15
Serguei Katkov3ed93b42019-07-15 08:26:45 +000020; CHECK: br i1 %{{.*}}, label %[[NEXT2:.*]], label %for.cond.for.end_crit_edge, !prof !18
21; CHECK: [[NEXT2]]:
Serguei Katkovc6c31da2019-07-22 05:15:34 +000022; CHECK: br i1 %c, label %{{.*}}, label %side_exit.loopexit, !prof !15
Serguei Katkov3ed93b42019-07-15 08:26:45 +000023; CHECK: br i1 %{{.*}}, label %for.body, label %{{.*}}, !prof !19
24
25define i32 @basic(i32* %p, i32 %k, i1 %c) #0 !prof !15 {
26entry:
27 %cmp3 = icmp slt i32 0, %k
28 br i1 %cmp3, label %for.body.lr.ph, label %for.end
29
30for.body.lr.ph: ; preds = %entry
31 br label %for.body
32
33for.body: ; preds = %for.body.lr.ph, %for.body
34 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %continue ]
35 %p.addr.04 = phi i32* [ %p, %for.body.lr.ph ], [ %incdec.ptr, %continue ]
36 %incdec.ptr = getelementptr inbounds i32, i32* %p.addr.04, i32 1
37 store i32 %i.05, i32* %p.addr.04, align 4
38 %inc = add nsw i32 %i.05, 1
39 %cmp = icmp slt i32 %inc, %k
40 br i1 %c, label %continue, label %side_exit, !prof !17
41
42continue:
43 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge, !prof !16
44
45for.cond.for.end_crit_edge: ; preds = %for.body
46 br label %for.end
47
48for.end: ; preds = %for.cond.for.end_crit_edge, %entry
49 %res = phi i32 [ 0, %entry ], [ %inc, %for.cond.for.end_crit_edge ]
50 ret i32 %res
51
52side_exit:
53 %rval = call i32(...) @llvm.experimental.deoptimize.i32() [ "deopt"(i32 %inc) ]
54 ret i32 %rval
55}
56
57declare i32 @llvm.experimental.deoptimize.i32(...)
58
59attributes #0 = { nounwind }
60attributes #1 = { nounwind optsize }
61
62!llvm.module.flags = !{!1}
63
64!1 = !{i32 1, !"ProfileSummary", !2}
65!2 = !{!3, !4, !5, !6, !7, !8, !9, !10}
66!3 = !{!"ProfileFormat", !"InstrProf"}
67!4 = !{!"TotalCount", i64 10}
68!5 = !{!"MaxCount", i64 3}
69!6 = !{!"MaxInternalCount", i64 1}
70!7 = !{!"MaxFunctionCount", i64 3}
71!8 = !{!"NumCounts", i64 2}
72!9 = !{!"NumFunctions", i64 2}
73!10 = !{!"DetailedSummary", !11}
74!11 = !{!12, !13, !14}
75!12 = !{i32 10000, i64 3, i32 2}
76!13 = !{i32 999000, i64 1, i32 10}
77!14 = !{i32 999999, i64 1, i32 10}
78!15 = !{!"function_entry_count", i64 1}
79!16 = !{!"branch_weights", i32 3001, i32 1001}
80!17 = !{!"branch_weights", i32 1, i32 0}
81
Serguei Katkovc6c31da2019-07-22 05:15:34 +000082; This is a weights of deopt side-exit.
83;CHECK: !15 = !{!"branch_weights", i32 1, i32 0}
84; This is a weights of latch and its copies.
85;CHECK: !16 = !{!"branch_weights", i32 3001, i32 1001}
86;CHECK: !17 = !{!"branch_weights", i32 2000, i32 1001}
87;CHECK: !18 = !{!"branch_weights", i32 999, i32 1001}
88;CHECK: !19 = !{!"branch_weights", i32 1, i32 1001}
Serguei Katkov3ed93b42019-07-15 08:26:45 +000089