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
4 ; The test verifies that counts are evenly distributed among branches with
7 ; +-----------+ +-----------+
8 ; | b3 [0] | <-- | b1 [1000] |
9 ; +-----------+ +-----------+
20 ; +-------------> | b4 [1000] |
23 @yydebug = dso_local global i32 0, align 4
25 ; Function Attrs: nounwind uwtable
26 define dso_local i32 @foo1(i32 %0, i32 %1) #0 {
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
36 call void @llvm.pseudoprobe(i64 7682762345278052905, i64 2, i32 0, i64 -1)
38 ; CHECK2: - b12: float = {{.*}}, int = {{.*}}, count = 500
41 call void @llvm.pseudoprobe(i64 7682762345278052905, i64 3, i32 0, i64 -1)
43 ; CHECK2: - b13: float = {{.*}}, int = {{.*}}, count = 500
46 call void @llvm.pseudoprobe(i64 7682762345278052905, i64 4, i32 0, i64 -1)
48 ; CHECK2: - b14: float = {{.*}}, int = {{.*}}, count = 1000
52 ; The test verifies that counts are evenly distributed when the entry basic
71 define dso_local i32 @foo2(i32 %0, i32 %1) #0 {
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
81 call void @llvm.pseudoprobe(i64 2494702099028631698, i64 2, i32 0, i64 -1)
83 ; CHECK2: - b22: float = {{.*}}, int = {{.*}}, count = 500
86 call void @llvm.pseudoprobe(i64 2494702099028631698, i64 3, i32 0, i64 -1)
88 ; CHECK2: - b23: float = {{.*}}, int = {{.*}}, count = 1000
92 ; The test verifies even count distribution in the presence of multiple sinks.
106 ; +--------+ +-----------+ |
107 ; | b5 [?] | <-- | b3 [?] | |
108 ; +--------+ +-----------+ |
119 ; +----------> | b6 [1000] |
123 define dso_local i32 @foo3(i32 %0, i32 %1) #0 {
125 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 1, i32 0, i64 -1)
126 %cmp = icmp ne i32 %0, 0
128 ; CHECK2: - b31: float = {{.*}}, int = {{.*}}, count = 1000
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
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
145 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 4, i32 0, i64 -1)
147 ; CHECK2: - b34: float = {{.*}}, int = {{.*}}, count = 1000
150 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 5, i32 0, i64 -1)
152 ; CHECK2: - b35: float = {{.*}}, int = {{.*}}, count = 0
155 call void @llvm.pseudoprobe(i64 -7908226060800700466, i64 6, i32 0, i64 -1)
157 ; CHECK2: - b36: float = {{.*}}, int = {{.*}}, count = 1000
162 ; Function Attrs: inaccessiblememonly nounwind willreturn
163 declare void @llvm.pseudoprobe(i64, i64, i32, i64) #4
165 attributes #0 = { noinline nounwind uwtable "use-sample-profile" }
166 attributes #4 = { inaccessiblememonly nounwind willreturn }
168 !llvm.pseudo_probe_desc = !{!7, !8, !9, !10}
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}