1 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-use-profi -sample-profile-file=%S/Inputs/profile-inference-rebalance.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-rebalance.prof | opt -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s --check-prefix=CHECK2
4 ; The test contains a "diamond" and a "triangle" that needs to be rebalanced
5 ; after basic profile inference.
12 ; +----------+ +----------------+
13 ; | b13 [10] | <-- | b12 [65536] |
14 ; +----------+ +----------------+
17 ; +----------+ +----------------+
18 ; | b16 [?] | <-- | b14 [65536] |
19 ; +----------+ +----------------+
22 ; | +----------------+
24 ; | +----------------+
27 ; | +----------------+
28 ; +------------> | b17 [65536] | -+
29 ; +----------------+ |
32 ; +----------------+ |
34 ; +----------------+ |
37 ; +----------------+ |
46 @yydebug = dso_local global i32 0, align 4
48 ; Function Attrs: nounwind uwtable
49 define dso_local i32 @countMultipliers(i32 %0, i32 %1) #0 {
51 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 1, i32 0, i64 -1)
52 %cmp = icmp ne i32 %0, 0
54 ; CHECK2: - b11: float = {{.*}}, int = {{.*}}, count = 65546
57 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 2, i32 0, i64 -1)
58 br i1 %cmp, label %b14, label %b13
59 ; CHECK2: - b12: float = {{.*}}, int = {{.*}}, count = 65546
62 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 3, i32 0, i64 -1)
64 ; CHECK2: - b13: float = {{.*}}, int = {{.*}}, count = 10
67 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 4, i32 0, i64 -1)
68 br i1 %cmp, label %b15, label %b16
69 ; CHECK: edge %b14 -> %b15 probability is 0x40000000 / 0x80000000 = 50.00%
70 ; CHECK: edge %b14 -> %b16 probability is 0x40000000 / 0x80000000 = 50.00%
71 ; CHECK2: - b14: float = {{.*}}, int = {{.*}}, count = 65536
74 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 5, i32 0, i64 -1)
76 ; CHECK2: - b15: float = {{.*}}, int = {{.*}}, count = 32768
79 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 6, i32 0, i64 -1)
81 ; CHECK2: - b16: float = {{.*}}, int = {{.*}}, count = 32768
84 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 7, i32 0, i64 -1)
85 br i1 %cmp, label %b18, label %b19
86 ; CHECK: edge %b17 -> %b18 probability is 0x40000000 / 0x80000000 = 50.00%
87 ; CHECK: edge %b17 -> %b19 probability is 0x40000000 / 0x80000000 = 50.00%
88 ; CHECK2: - b17: float = {{.*}}, int = {{.*}}, count = 65536
91 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 8, i32 0, i64 -1)
93 ; CHECK2: - b18: float = {{.*}}, int = {{.*}}, count = 32768
96 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 9, i32 0, i64 -1)
98 ; CHECK2: - b19: float = {{.*}}, int = {{.*}}, count = 65536
101 call void @llvm.pseudoprobe(i64 -5758218299531803684, i64 10, i32 0, i64 -1)
103 ; CHECK2: - b110: float = {{.*}}, int = {{.*}}, count = 65536
107 ; The test contains a triangle comprised of dangling blocks.
121 ; +--------+ | +-----------+ |
122 ; | b4 [?] | <-----+- | b2 [?] | |
123 ; +--------+ | +-----------+ |
127 ; | | +-----------+ |
134 ; +---------------> | b5 [2100] | <+
137 define dso_local i32 @countMultipliers2(i32 %0, i32 %1) #0 {
139 call void @llvm.pseudoprobe(i64 2506109673213838996, i64 1, i32 0, i64 -1)
140 %cmp = icmp ne i32 %0, 0
141 br i1 %cmp, label %b1, label %b5
142 ; CHECK: edge %b0 -> %b1 probability is 0x79e79e7a / 0x80000000 = 95.24% [HOT edge]
143 ; CHECK: edge %b0 -> %b5 probability is 0x06186186 / 0x80000000 = 4.76%
144 ; CHECK2: - b0: float = {{.*}}, int = {{.*}}, count = 2100
147 call void @llvm.pseudoprobe(i64 2506109673213838996, i64 2, i32 0, i64 -1)
148 br i1 %cmp, label %b2, label %b3
149 ; CHECK: edge %b1 -> %b2 probability is 0x40000000 / 0x80000000 = 50.00%
150 ; CHECK: edge %b1 -> %b3 probability is 0x40000000 / 0x80000000 = 50.00%
151 ; CHECK2: - b1: float = {{.*}}, int = {{.*}}, count = 2000
154 call void @llvm.pseudoprobe(i64 2506109673213838996, i64 3, i32 0, i64 -1)
155 br i1 %cmp, label %b3, label %b4
156 ; CHECK: edge %b2 -> %b3 probability is 0x40000000 / 0x80000000 = 50.00%
157 ; CHECK: edge %b2 -> %b4 probability is 0x40000000 / 0x80000000 = 50.00%
158 ; CHECK2: - b2: float = {{.*}}, int = {{.*}}, count = 1000
161 call void @llvm.pseudoprobe(i64 2506109673213838996, i64 4, i32 0, i64 -1)
163 ; CHECK: edge %b3 -> %b5 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
164 ; CHECK2: - b3: float = {{.*}}, int = {{.*}}, count = 1500
167 call void @llvm.pseudoprobe(i64 2506109673213838996, i64 5, i32 0, i64 -1)
169 ; CHECK: edge %b4 -> %b5 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
170 ; CHECK2: - b4: float = {{.*}}, int = {{.*}}, count = 500
173 call void @llvm.pseudoprobe(i64 2506109673213838996, i64 6, i32 0, i64 -1)
175 ; CHECK2: - b5: float = {{.*}}, int = {{.*}}, count = 2100
180 ; The test contains a dangling subgraph that contains an exit dangling block.
181 ; No rebalancing is necessary here.
189 ; +---------+ +-----------+
190 ; | b34 [?] | <-- | b32 [100] |
191 ; +---------+ +-----------+
199 define dso_local i32 @countMultipliers3(i32 %0, i32 %1) #0 {
201 call void @llvm.pseudoprobe(i64 -544905447084884130, i64 1, i32 0, i64 -1)
203 ; CHECK2: - b31: float = {{.*}}, int = {{.*}}, count = 100
206 call void @llvm.pseudoprobe(i64 -544905447084884130, i64 2, i32 0, i64 -1)
207 %cmp = icmp ne i32 %0, 0
208 br i1 %cmp, label %b34, label %b33
209 ; CHECK: edge %b32 -> %b34 probability is 0x00000000 / 0x80000000 = 0.00%
210 ; CHECK: edge %b32 -> %b33 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
211 ; CHECK2: - b32: float = {{.*}}, int = {{.*}}, count = 100
214 call void @llvm.pseudoprobe(i64 -544905447084884130, i64 3, i32 0, i64 -1)
216 ; CHECK2: - b33: float = {{.*}}, int = {{.*}}, count = 100
219 call void @llvm.pseudoprobe(i64 -544905447084884130, i64 4, i32 0, i64 -1)
221 ; CHECK2: - b34: float = {{.*}}, int = {{.*}}, count = 0
225 ; Another dangling subgraph (b42, b43, b44) containing a single dangling block.
227 ; +----------+ +-----------+
228 ; +- | b42 [50] | <-- | b40 [100] |
229 ; | +----------+ +-----------+
240 ; | +------------> | b43 [?] |
246 ; +-----------------> | b44 [100] |
249 define dso_local i32 @countMultipliers4(i32 %0, i32 %1) #0 {
251 call void @llvm.pseudoprobe(i64 -2989539179265513123, i64 1, i32 0, i64 -1)
252 %cmp = icmp ne i32 %0, 0
253 br i1 %cmp, label %b41, label %b42
254 ; CHECK2: - b40: float = {{.*}}, int = {{.*}}, count = 100
257 call void @llvm.pseudoprobe(i64 -2989539179265513123, i64 2, i32 0, i64 -1)
259 ; CHECK2: - b41: float = {{.*}}, int = {{.*}}, count = 50
262 call void @llvm.pseudoprobe(i64 -2989539179265513123, i64 3, i32 0, i64 -1)
263 br i1 %cmp, label %b43, label %b44
264 ; CHECK: edge %b42 -> %b43 probability is 0x40000000 / 0x80000000 = 50.00%
265 ; CHECK: edge %b42 -> %b44 probability is 0x40000000 / 0x80000000 = 50.00%
266 ; CHECK2: - b42: float = {{.*}}, int = {{.*}}, count = 50
269 call void @llvm.pseudoprobe(i64 -2989539179265513123, i64 4, i32 0, i64 -1)
271 ; CHECK2: - b43: float = {{.*}}, int = {{.*}}, count = 75
274 call void @llvm.pseudoprobe(i64 -2989539179265513123, i64 5, i32 0, i64 -1)
276 ; CHECK2: - b44: float = {{.*}}, int = {{.*}}, count = 100
279 ; Function Attrs: inaccessiblememonly nounwind willreturn
280 declare void @llvm.pseudoprobe(i64, i64, i32, i64) #4
282 attributes #0 = { noinline nounwind uwtable "use-sample-profile" }
283 attributes #4 = { inaccessiblememonly nounwind willreturn }
285 !llvm.pseudo_probe_desc = !{!7, !8, !9, !10}
287 !7 = !{i64 -5758218299531803684, i64 223598586707, !"countMultipliers", null}
288 !8 = !{i64 2506109673213838996, i64 2235985, !"countMultipliers2", null}
289 !9 = !{i64 -544905447084884130, i64 22985, !"countMultipliers3", null}
290 !10 = !{i64 -2989539179265513123, i64 2298578, !"countMultipliers4", null}