1 ; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-use-profi -sample-profile-file=%S/Inputs/profile-inference-islands.prof -S -o %t
2 ; RUN: FileCheck %s < %t -check-prefix=CHECK-ENTRY-COUNT
3 ; RUN: opt < %t -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
6 ; The test contains an isolated flow component ("island") that needs to be
7 ; reconnected to the entry point via edges with a positive flow.
8 ; The corresponding CFG is shown below:
10 ; +--------+ +--------+ +----------+
11 ; | b6 [1] | <-- | b4 [1] | <-- | b1 [1] |
12 ; +--------+ +--------+ +----------+
16 ; +--------+ +----------+
17 ; | b5 [0] | | b2 [100] | <+
18 ; +--------+ +----------+ |
33 ; Function Attrs: nounwind uwtable
34 define dso_local i32 @islands_1(i32 %0, i32 %1) #0 {
36 call void @llvm.pseudoprobe(i64 -5646793257986063976, i64 1, i32 0, i64 -1)
37 %cmp = icmp ne i32 %0, 0
38 br i1 %cmp, label %b2, label %b4
39 ; CHECK: - b1: float = {{.*}}, int = {{.*}}, count = 2
42 call void @llvm.pseudoprobe(i64 -5646793257986063976, i64 2, i32 0, i64 -1)
44 ; CHECK: - b2: float = {{.*}}, int = {{.*}}, count = 101
47 call void @llvm.pseudoprobe(i64 -5646793257986063976, i64 3, i32 0, i64 -1)
48 br i1 %cmp, label %b2, label %b7
49 ; CHECK: - b3: float = {{.*}}, int = {{.*}}, count = 101
52 call void @llvm.pseudoprobe(i64 -5646793257986063976, i64 4, i32 0, i64 -1)
53 br i1 %cmp, label %b5, label %b6
54 ; CHECK: - b4: float = {{.*}}, int = {{.*}}, count = 1
57 call void @llvm.pseudoprobe(i64 -5646793257986063976, i64 5, i32 0, i64 -1)
59 ; CHECK: - b5: float = {{.*}}, int = {{.*}}, count = 0
62 call void @llvm.pseudoprobe(i64 -5646793257986063976, i64 6, i32 0, i64 -1)
64 ; CHECK: - b6: float = {{.*}}, int = {{.*}}, count = 1
67 call void @llvm.pseudoprobe(i64 -5646793257986063976, i64 7, i32 0, i64 -1)
69 ; CHECK: - b7: float = {{.*}}, int = {{.*}}, count = 1
73 ; Another test with an island.
97 ; Function Attrs: nounwind uwtable
98 define dso_local i32 @islands_2(i32 %0, i32 %1) #1 {
100 call void @llvm.pseudoprobe(i64 -7683376842751444845, i64 1, i32 0, i64 -1)
101 %cmp = icmp ne i32 %0, 0
103 ; CHECK: - b1: float = {{.*}}, int = {{.*}}, count = 1
106 call void @llvm.pseudoprobe(i64 -7683376842751444845, i64 2, i32 0, i64 -1)
108 ; CHECK: - b2: float = {{.*}}, int = {{.*}}, count = 10001
111 call void @llvm.pseudoprobe(i64 -7683376842751444845, i64 3, i32 0, i64 -1)
112 br i1 %cmp, label %b2, label %b4
113 ; CHECK: - b3: float = {{.*}}, int = {{.*}}, count = 10001
116 call void @llvm.pseudoprobe(i64 -7683376842751444845, i64 4, i32 0, i64 -1)
118 ; CHECK: - b4: float = {{.*}}, int = {{.*}}, count = 1
122 ; The test verifies that the island is connected to the entry block via a
123 ; cheapest path (that is, passing through blocks with large counts).
125 ; +---------+ +---------+ +----------+ +--------+
126 ; | b8 [10] | <-- | b3 [10] | <-- | b1 [10] | --> | b4 [0] |
127 ; +---------+ +---------+ +----------+ +--------+
137 ; | +-------------------------+
138 ; +-----------> | b5 [100] |
139 ; +-------------------------+
153 ; Function Attrs: nounwind uwtable
154 define dso_local i32 @islands_3(i32 %0, i32 %1) #1 {
156 call void @llvm.pseudoprobe(i64 -9095645063288297061, i64 1, i32 0, i64 -1)
157 %cmp = icmp ne i32 %0, 0
158 switch i32 %1, label %b2 [
162 ; CHECK: - b1: float = {{.*}}, int = {{.*}}, count = 11
165 call void @llvm.pseudoprobe(i64 -9095645063288297061, i64 2, i32 0, i64 -1)
167 ; CHECK: - b2: float = {{.*}}, int = {{.*}}, count = 0
170 call void @llvm.pseudoprobe(i64 -9095645063288297061, i64 3, i32 0, i64 -1)
171 br i1 %cmp, label %b8, label %b5
172 ; CHECK: - b3: float = {{.*}}, int = {{.*}}, count = 11
175 call void @llvm.pseudoprobe(i64 -9095645063288297061, i64 4, i32 0, i64 -1)
177 ; CHECK: - b4: float = {{.*}}, int = {{.*}}, count = 0
180 call void @llvm.pseudoprobe(i64 -9095645063288297061, i64 5, i32 0, i64 -1)
182 ; CHECK: - b5: float = {{.*}}, int = {{.*}}, count = 1001
185 call void @llvm.pseudoprobe(i64 -9095645063288297061, i64 6, i32 0, i64 -1)
186 br i1 %cmp, label %b7, label %b5
187 ; CHECK: - b6: float = {{.*}}, int = {{.*}}, count = 1001
190 call void @llvm.pseudoprobe(i64 -9095645063288297061, i64 7, i32 0, i64 -1)
192 ; CHECK: - b7: float = {{.*}}, int = {{.*}}, count = 1
195 call void @llvm.pseudoprobe(i64 -9095645063288297061, i64 8, i32 0, i64 -1)
197 ; CHECK: - b8: float = {{.*}}, int = {{.*}}, count = 10
200 declare void @llvm.pseudoprobe(i64, i64, i32, i64) #2
202 attributes #0 = { noinline nounwind uwtable "use-sample-profile"}
203 attributes #1 = { noinline nounwind uwtable "use-sample-profile"}
204 attributes #2 = { nounwind }
206 !llvm.pseudo_probe_desc = !{!7, !8}
208 !7 = !{i64 -5646793257986063976, i64 120879332589, !"islands_1"}
209 !8 = !{i64 -7683376842751444845, i64 69495280403, !"islands_2"}
210 !9 = !{i64 -9095645063288297061, i64 156608410269, !"islands_3"}
212 ; CHECK-ENTRY-COUNT: = !{!"function_entry_count", i64 2}