1 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-use-profi -sample-profile-file=%S/Inputs/profile-inference.prof | opt -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
2 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-use-profi -sample-profile-file=%S/Inputs/profile-inference.prof | opt -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s --check-prefix=CHECK2
4 ; The test verifies that profile inference correctly builds branch probabilities
5 ; from sampling-based block counts.
7 ; +---------+ +----------+
8 ; | b3 [40] | <-- | b1 [100] |
9 ; +---------+ +----------+
17 @yydebug = dso_local global i32 0, align 4
19 ; Function Attrs: nounwind uwtable
20 define dso_local i32 @test_1() #0 {
22 call void @llvm.pseudoprobe(i64 7964825052912775246, i64 1, i32 0, i64 -1)
23 %0 = load i32, ptr @yydebug, align 4
24 %cmp = icmp ne i32 %0, 0
25 br i1 %cmp, label %b2, label %b3
26 ; CHECK: edge b1 -> b2 probability is 0x4ccccccd / 0x80000000 = 60.00%
27 ; CHECK: edge b1 -> b3 probability is 0x33333333 / 0x80000000 = 40.00%
28 ; CHECK2: - b1: float = {{.*}}, int = {{.*}}, count = 100
31 call void @llvm.pseudoprobe(i64 7964825052912775246, i64 2, i32 0, i64 -1)
33 ; CHECK2: - b2: float = {{.*}}, int = {{.*}}, count = 60
36 call void @llvm.pseudoprobe(i64 7964825052912775246, i64 3, i32 0, i64 -1)
38 ; CHECK2: - b3: float = {{.*}}, int = {{.*}}, count = 40
42 ; The test verifies that profile inference correctly builds branch probabilities
43 ; from sampling-based block counts in the presence of "dangling" probes (whose
44 ; block counts are missing).
46 ; +---------+ +----------+
47 ; | b3 [10] | <-- | b1 [100] |
48 ; +---------+ +----------+
56 ; Function Attrs: nounwind uwtable
57 define dso_local i32 @test_2() #0 {
59 call void @llvm.pseudoprobe(i64 -6216829535442445639, i64 1, i32 0, i64 -1)
60 %0 = load i32, ptr @yydebug, align 4
61 %cmp = icmp ne i32 %0, 0
62 br i1 %cmp, label %b2, label %b3
63 ; CHECK: edge b1 -> b2 probability is 0x73333333 / 0x80000000 = 90.00%
64 ; CHECK: edge b1 -> b3 probability is 0x0ccccccd / 0x80000000 = 10.00%
65 ; CHECK2: - b1: float = {{.*}}, int = {{.*}}, count = 100
68 call void @llvm.pseudoprobe(i64 -6216829535442445639, i64 2, i32 0, i64 -1)
70 ; CHECK2: - b2: float = {{.*}}, int = {{.*}}, count = 90
73 call void @llvm.pseudoprobe(i64 -6216829535442445639, i64 3, i32 0, i64 -1)
76 ; CHECK2: - b3: float = {{.*}}, int = {{.*}}, count = 10
79 ; The test verifies that profi is able to infer block counts from hot subgraphs.
81 ; +---------+ +---------+
82 ; | b4 [?] | <-- | b1 [?] |
83 ; +---------+ +---------+
87 ; +---------+ +---------+
88 ; | b5 [89] | | b2 [?] |
89 ; +---------+ +---------+
97 ; Function Attrs: nounwind uwtable
98 define dso_local i32 @test_3() #0 {
100 call void @llvm.pseudoprobe(i64 1649282507922421973, i64 1, i32 0, i64 -1)
101 %0 = load i32, ptr @yydebug, align 4
102 %cmp = icmp ne i32 %0, 0
103 br i1 %cmp, label %b2, label %b4
104 ; CHECK: edge b1 -> b2 probability is 0x10505050 / 0x80000000 = 12.75%
105 ; CHECK: edge b1 -> b4 probability is 0x6fafafb0 / 0x80000000 = 87.25%
106 ; CHECK2: - b1: float = {{.*}}, int = {{.*}}, count = 102
109 call void @llvm.pseudoprobe(i64 1649282507922421973, i64 2, i32 0, i64 -1)
111 ; CHECK: edge b2 -> b3 probability is 0x80000000 / 0x80000000 = 100.00%
112 ; CHECK2: - b2: float = {{.*}}, int = {{.*}}, count = 13
115 call void @llvm.pseudoprobe(i64 1649282507922421973, i64 3, i32 0, i64 -1)
117 ; CHECK2: - b3: float = {{.*}}, int = {{.*}}, count = 13
120 call void @llvm.pseudoprobe(i64 1649282507922421973, i64 4, i32 0, i64 -1)
122 ; CHECK: edge b4 -> b5 probability is 0x80000000 / 0x80000000 = 100.00%
123 ; CHECK2: - b4: float = {{.*}}, int = {{.*}}, count = 89
126 call void @llvm.pseudoprobe(i64 1649282507922421973, i64 5, i32 0, i64 -1)
128 ; CHECK2: - b5: float = {{.*}}, int = {{.*}}, count = 89
132 ; A larger test to verify that profile inference correctly identifies hot parts
133 ; of the control-flow graph.
141 ; +--------+ +-----------+
142 ; | b3 [1] | <-- | b2 [5993] |
143 ; +--------+ +-----------+
147 ; | +-----------+ +--------+
148 ; | | b4 [5992] | --> | b6 [?] |
149 ; | +-----------+ +--------+
166 ; | | b8 [5992] | <-----+
172 ; +----------> | b9 [?] |
175 ; Function Attrs: nounwind uwtable
176 define dso_local i32 @sum_of_squares() #0 {
178 call void @llvm.pseudoprobe(i64 -907520326213521421, i64 1, i32 0, i64 -1)
179 %0 = load i32, ptr @yydebug, align 4
180 %cmp = icmp ne i32 %0, 0
182 ; CHECK: edge b1 -> b2 probability is 0x80000000 / 0x80000000 = 100.00%
183 ; CHECK2: - b1: float = {{.*}}, int = {{.*}}, count = 5993
186 call void @llvm.pseudoprobe(i64 -907520326213521421, i64 2, i32 0, i64 -1)
187 br i1 %cmp, label %b4, label %b3
188 ; CHECK: edge b2 -> b4 probability is 0x7ffa8844 / 0x80000000 = 99.98%
189 ; CHECK: edge b2 -> b3 probability is 0x000577bc / 0x80000000 = 0.02%
190 ; CHECK2: - b2: float = {{.*}}, int = {{.*}}, count = 5993
193 call void @llvm.pseudoprobe(i64 -907520326213521421, i64 3, i32 0, i64 -1)
195 ; CHECK: edge b3 -> b9 probability is 0x80000000 / 0x80000000 = 100.00%
196 ; CHECK2: - b3: float = {{.*}}, int = {{.*}}, count = 1
199 call void @llvm.pseudoprobe(i64 -907520326213521421, i64 4, i32 0, i64 -1)
200 br i1 %cmp, label %b5, label %b6
201 ; CHECK: edge b4 -> b5 probability is 0x80000000 / 0x80000000 = 100.00%
202 ; CHECK: edge b4 -> b6 probability is 0x00000000 / 0x80000000 = 0.00%
203 ; CHECK2: - b4: float = {{.*}}, int = {{.*}}, count = 5992
206 call void @llvm.pseudoprobe(i64 -907520326213521421, i64 5, i32 0, i64 -1)
208 ; CHECK: edge b5 -> b7 probability is 0x80000000 / 0x80000000 = 100.00%
209 ; CHECK2: - b5: float = {{.*}}, int = {{.*}}, count = 5992
212 call void @llvm.pseudoprobe(i64 -907520326213521421, i64 6, i32 0, i64 -1)
214 ; CHECK: edge b6 -> b8 probability is 0x80000000 / 0x80000000 = 100.00%
215 ; CHECK2: - b6: float = {{.*}}, int = {{.*}}, count = 0
218 call void @llvm.pseudoprobe(i64 -907520326213521421, i64 7, i32 0, i64 -1)
220 ; CHECK: edge b7 -> b8 probability is 0x80000000 / 0x80000000 = 100.00%
221 ; CHECK2: - b7: float = {{.*}}, int = {{.*}}, count = 5992
224 call void @llvm.pseudoprobe(i64 -907520326213521421, i64 8, i32 0, i64 -1)
226 ; CHECK: edge b8 -> b9 probability is 0x80000000 / 0x80000000 = 100.00%
227 ; CHECK2: - b8: float = {{.*}}, int = {{.*}}, count = 5992
230 call void @llvm.pseudoprobe(i64 -907520326213521421, i64 9, i32 0, i64 -1)
233 ; CHECK2: - b9: float = {{.*}}, int = {{.*}}, count = 5993
236 declare void @llvm.pseudoprobe(i64, i64, i32, i64) #1
238 attributes #0 = { noinline nounwind uwtable "use-sample-profile"}
239 attributes #1 = { nounwind }
241 !llvm.pseudo_probe_desc = !{!6, !7, !8, !9}
243 !6 = !{i64 7964825052912775246, i64 4294967295, !"test_1", null}
244 !7 = !{i64 -6216829535442445639, i64 37753817093, !"test_2", null}
245 !8 = !{i64 1649282507922421973, i64 69502983527, !"test_3", null}
246 !9 = !{i64 -907520326213521421, i64 175862120757, !"sum_of_squares", null}