Debian Codegraph @

llvm/test/Transforms/SampleProfile/profile-inference-even-count-distribution.ll

raw
1 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-use-profi -sample-profile-file=%S/Inputs/profile-inference-even-count-distribution.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-even-count-distribution.prof | opt -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s --check-prefix=CHECK2
3
4 ; The test verifies that counts are evenly distributed among branches with
5 ; equal weights.
6 ;
7 ; +-----------+ +-----------+
8 ; | b3 [0] | <-- | b1 [1000] |
9 ; +-----------+ +-----------+
10 ; | |
11 ; | |
12 ; | v
13 ; | +-----------+
14 ; | | b2 [0] |
15 ; | +-----------+
16 ; | |
17 ; | |
18 ; | v
19 ; | +-----------+
20 ; +-------------> | b4 [1000] |
21 ; +-----------+
22
23 @yydebug = dso_local global i32 0, align 4
24
25 ; Function Attrs: nounwind uwtable
26 define dso_local i32 @foo1(i32 %0, i32 %1) #0 {
27 b11:
28 call void @llvm.pseudoprobe(i64 7682762345278052905, i64 1, i32 0, i64 -1)
29 %cmp = icmp ne i32 %0, 0
30 br i1 %cmp, label %b12, label %b13
31 ; CHECK: edge %b11 -> %b12 probability is 0x40000000 / 0x80000000 = 50.00%
32 ; CHECK: edge %b11 -> %b13 probability is 0x40000000 / 0x80000000 = 50.00%
33 ; CHECK2: - b11: float = {{.*}}, int = {{.*}}, count = 1000
34
35 b12:
36 call void @llvm.pseudoprobe(i64 7682762345278052905, i64 2, i32 0, i64 -1)
37 br label %b14
38 ; CHECK2: - b12: float = {{.*}}, int = {{.*}}, count = 500
39
40 b13:
41 call void @llvm.pseudoprobe(i64 7682762345278052905, i64 3, i32 0, i64 -1)
42 br label %b14
43 ; CHECK2: - b13: float = {{.*}}, int = {{.*}}, count = 500
44
45 b14:
46 call void @llvm.pseudoprobe(i64 7682762345278052905, i64 4, i32 0, i64 -1)
47 ret i32 %1
48 ; CHECK2: - b14: float = {{.*}}, int = {{.*}}, count = 1000
49 }
50
51
52 ; The test verifies that counts are evenly distributed when the entry basic
53 ; block is dangling.
54 ;
55 ; +-----------+
56 ; | b1 [?] | -+
57 ; +-----------+ |
58 ; | |
59 ; | |
60 ; v |
61 ; +-----------+ |
62 ; | b2 [?] | |
63 ; +-----------+ |
64 ; | |
65 ; | |
66 ; v |
67 ; +-----------+ |
68 ; | b3 [1000] | <+
69 ; +-----------+
70
71 define dso_local i32 @foo2(i32 %0, i32 %1) #0 {
72 b21:
73 call void @llvm.pseudoprobe(i64 2494702099028631698, i64 1, i32 0, i64 -1)
74 %cmp = icmp ne i32 %0, 0
75 br i1 %cmp, label %b22, label %b23
76 ; CHECK: edge %b21 -> %b22 probability is 0x40000000 / 0x80000000 = 50.00%
77 ; CHECK: edge %b21 -> %b23 probability is 0x40000000 / 0x80000000 = 50.00%
78 ; CHECK2: - b21: float = {{.*}}, int = {{.*}}, count = 1000
79
80 b22:
81 call void @llvm.pseudoprobe(i64 2494702099028631698, i64 2, i32 0, i64 -1)
82 br label %b23
83 ; CHECK2: - b22: float = {{.*}}, int = {{.*}}, count = 500
84
85 b23:
86 call void @llvm.pseudoprobe(i64 2494702099028631698, i64 3, i32 0, i64 -1)
87 ret i32 %1
88 ; CHECK2: - b23: float = {{.*}}, int = {{.*}}, count = 1000
89
90 }
91
92 ; The test verifies even count distribution in the presence of multiple sinks.
93 ;
94 ; +-----------+
95 ; | b1 [1000] |
96 ; +-----------+
97 ; |
98 ; |
99 ; v
100 ; +-----------+
101 ; | b2 [?] | -+
102 ; +-----------+ |
103 ; | |
104 ; | |
105 ; v |
106 ; +--------+ +-----------+ |
107 ; | b5 [?] | <-- | b3 [?] | |
108 ; +--------+ +-----------+ |
109 ; | | |
110 ; | | |
111 ; | v |
112 ; | +-----------+ |
113 ; | | b4 [1000] | <+
114 ; | +-----------+
115 ; | |
116 ; | |
117 ; | v
118 ; | +-----------+
119 ; +----------> | b6 [1000] |
120 ; +-----------+
121 ;
122
123 define dso_local i32 @foo3(i32 %0, i32 %1) #0 {
124 b31:
125 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 1, i32 0, i64 -1)
126 %cmp = icmp ne i32 %0, 0
127 br label %b32
128 ; CHECK2: - b31: float = {{.*}}, int = {{.*}}, count = 1000
129
130 b32:
131 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 2, i32 0, i64 -1)
132 br i1 %cmp, label %b33, label %b34
133 ; CHECK: edge %b32 -> %b33 probability is 0x40000000 / 0x80000000 = 50.00%
134 ; CHECK: edge %b32 -> %b34 probability is 0x40000000 / 0x80000000 = 50.00%
135 ; CHECK2: - b32: float = {{.*}}, int = {{.*}}, count = 1000
136
137 b33:
138 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 3, i32 0, i64 -1)
139 br i1 %cmp, label %b35, label %b34
140 ; CHECK: edge %b33 -> %b35 probability is 0x00000000 / 0x80000000 = 0.00%
141 ; CHECK: edge %b33 -> %b34 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
142 ; CHECK2: - b33: float = {{.*}}, int = {{.*}}, count = 500
143
144 b34:
145 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 4, i32 0, i64 -1)
146 br label %b36
147 ; CHECK2: - b34: float = {{.*}}, int = {{.*}}, count = 1000
148
149 b35:
150 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 5, i32 0, i64 -1)
151 br label %b36
152 ; CHECK2: - b35: float = {{.*}}, int = {{.*}}, count = 0
153
154 b36:
155 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 6, i32 0, i64 -1)
156 ret i32 %1
157 ; CHECK2: - b36: float = {{.*}}, int = {{.*}}, count = 1000
158 }
159
160
161
162 ; Function Attrs: inaccessiblememonly nounwind willreturn
163 declare void @llvm.pseudoprobe(i64, i64, i32, i64) #4
164
165 attributes #0 = { noinline nounwind uwtable "use-sample-profile" }
166 attributes #4 = { inaccessiblememonly nounwind willreturn }
167
168 !llvm.pseudo_probe_desc = !{!7, !8, !9, !10}
169
170 !7 = !{i64 7682762345278052905, i64 157181141624, !"foo1", null}
171 !8 = !{i64 2494702099028631698, i64 208782362068, !"foo2", null}
172 !9 = !{i64 -7908226060800700466, i64 189901498683, !"foo3", null}
173 !10 = !{i64 -6882312132165544686, i64 241030178952, !"foo4", null}