| 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 |
| 3 |
|
| 4 |
; The test verifies that profile inference correctly builds branch probabilities |
| 5 |
; from sampling-based block counts. |
| 6 |
; |
| 7 |
; +---------+ +----------+ |
| 8 |
; | b3 [40] | <-- | b1 [100] | |
| 9 |
; +---------+ +----------+ |
| 10 |
; | |
| 11 |
; | |
| 12 |
; v |
| 13 |
; +----------+ |
| 14 |
; | b2 [60] | |
| 15 |
; +----------+ |
| 16 |
|
| 17 |
@yydebug = dso_local global i32 0, align 4 |
| 18 |
|
| 19 |
; Function Attrs: nounwind uwtable |
| 20 |
define dso_local i32 @test_1() #0 { |
| 21 |
b1: |
| 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 |
| 29 |
|
| 30 |
b2: |
| 31 |
call void @llvm.pseudoprobe(i64 7964825052912775246, i64 2, i32 0, i64 -1) |
| 32 |
ret i32 %0 |
| 33 |
; CHECK2: - b2: float = {{.*}}, int = {{.*}}, count = 60 |
| 34 |
|
| 35 |
b3: |
| 36 |
call void @llvm.pseudoprobe(i64 7964825052912775246, i64 3, i32 0, i64 -1) |
| 37 |
ret i32 %0 |
| 38 |
; CHECK2: - b3: float = {{.*}}, int = {{.*}}, count = 40 |
| 39 |
} |
| 40 |
|
| 41 |
|
| 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). |
| 45 |
; |
| 46 |
; +---------+ +----------+ |
| 47 |
; | b3 [10] | <-- | b1 [100] | |
| 48 |
; +---------+ +----------+ |
| 49 |
; | |
| 50 |
; | |
| 51 |
; v |
| 52 |
; +----------+ |
| 53 |
; | b2 [?] | |
| 54 |
; +----------+ |
| 55 |
|
| 56 |
; Function Attrs: nounwind uwtable |
| 57 |
define dso_local i32 @test_2() #0 { |
| 58 |
b1: |
| 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 |
| 66 |
|
| 67 |
b2: |
| 68 |
call void @llvm.pseudoprobe(i64 -6216829535442445639, i64 2, i32 0, i64 -1) |
| 69 |
ret i32 %0 |
| 70 |
; CHECK2: - b2: float = {{.*}}, int = {{.*}}, count = 90 |
| 71 |
|
| 72 |
b3: |
| 73 |
call void @llvm.pseudoprobe(i64 -6216829535442445639, i64 3, i32 0, i64 -1) |
| 74 |
ret i32 %0 |
| 75 |
} |
| 76 |
; CHECK2: - b3: float = {{.*}}, int = {{.*}}, count = 10 |
| 77 |
|
| 78 |
|
| 79 |
; The test verifies that profi is able to infer block counts from hot subgraphs. |
| 80 |
; |
| 81 |
; +---------+ +---------+ |
| 82 |
; | b4 [?] | <-- | b1 [?] | |
| 83 |
; +---------+ +---------+ |
| 84 |
; | | |
| 85 |
; | | |
| 86 |
; v v |
| 87 |
; +---------+ +---------+ |
| 88 |
; | b5 [89] | | b2 [?] | |
| 89 |
; +---------+ +---------+ |
| 90 |
; | |
| 91 |
; | |
| 92 |
; v |
| 93 |
; +---------+ |
| 94 |
; | b3 [13] | |
| 95 |
; +---------+ |
| 96 |
|
| 97 |
; Function Attrs: nounwind uwtable |
| 98 |
define dso_local i32 @test_3() #0 { |
| 99 |
b1: |
| 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 |
| 107 |
|
| 108 |
b2: |
| 109 |
call void @llvm.pseudoprobe(i64 1649282507922421973, i64 2, i32 0, i64 -1) |
| 110 |
br label %b3 |
| 111 |
; CHECK: edge %b2 -> %b3 probability is 0x80000000 / 0x80000000 = 100.00% |
| 112 |
; CHECK2: - b2: float = {{.*}}, int = {{.*}}, count = 13 |
| 113 |
|
| 114 |
b3: |
| 115 |
call void @llvm.pseudoprobe(i64 1649282507922421973, i64 3, i32 0, i64 -1) |
| 116 |
ret i32 %0 |
| 117 |
; CHECK2: - b3: float = {{.*}}, int = {{.*}}, count = 13 |
| 118 |
|
| 119 |
b4: |
| 120 |
call void @llvm.pseudoprobe(i64 1649282507922421973, i64 4, i32 0, i64 -1) |
| 121 |
br label %b5 |
| 122 |
; CHECK: edge %b4 -> %b5 probability is 0x80000000 / 0x80000000 = 100.00% |
| 123 |
; CHECK2: - b4: float = {{.*}}, int = {{.*}}, count = 89 |
| 124 |
|
| 125 |
b5: |
| 126 |
call void @llvm.pseudoprobe(i64 1649282507922421973, i64 5, i32 0, i64 -1) |
| 127 |
ret i32 %0 |
| 128 |
; CHECK2: - b5: float = {{.*}}, int = {{.*}}, count = 89 |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
; A larger test to verify that profile inference correctly identifies hot parts |
| 133 |
; of the control-flow graph. |
| 134 |
; |
| 135 |
; +-----------+ |
| 136 |
; | b1 [?] | |
| 137 |
; +-----------+ |
| 138 |
; | |
| 139 |
; | |
| 140 |
; v |
| 141 |
; +--------+ +-----------+ |
| 142 |
; | b3 [1] | <-- | b2 [5993] | |
| 143 |
; +--------+ +-----------+ |
| 144 |
; | | |
| 145 |
; | | |
| 146 |
; | v |
| 147 |
; | +-----------+ +--------+ |
| 148 |
; | | b4 [5992] | --> | b6 [?] | |
| 149 |
; | +-----------+ +--------+ |
| 150 |
; | | | |
| 151 |
; | | | |
| 152 |
; | v | |
| 153 |
; | +-----------+ | |
| 154 |
; | | b5 [5992] | | |
| 155 |
; | +-----------+ | |
| 156 |
; | | | |
| 157 |
; | | | |
| 158 |
; | v | |
| 159 |
; | +-----------+ | |
| 160 |
; | | b7 [?] | | |
| 161 |
; | +-----------+ | |
| 162 |
; | | | |
| 163 |
; | | | |
| 164 |
; | v | |
| 165 |
; | +-----------+ | |
| 166 |
; | | b8 [5992] | <-----+ |
| 167 |
; | +-----------+ |
| 168 |
; | | |
| 169 |
; | | |
| 170 |
; | v |
| 171 |
; | +-----------+ |
| 172 |
; +----------> | b9 [?] | |
| 173 |
; +-----------+ |
| 174 |
|
| 175 |
; Function Attrs: nounwind uwtable |
| 176 |
define dso_local i32 @sum_of_squares() #0 { |
| 177 |
b1: |
| 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 |
| 181 |
br label %b2 |
| 182 |
; CHECK: edge %b1 -> %b2 probability is 0x80000000 / 0x80000000 = 100.00% |
| 183 |
; CHECK2: - b1: float = {{.*}}, int = {{.*}}, count = 5993 |
| 184 |
|
| 185 |
b2: |
| 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 |
| 191 |
|
| 192 |
b3: |
| 193 |
call void @llvm.pseudoprobe(i64 -907520326213521421, i64 3, i32 0, i64 -1) |
| 194 |
br label %b9 |
| 195 |
; CHECK: edge %b3 -> %b9 probability is 0x80000000 / 0x80000000 = 100.00% |
| 196 |
; CHECK2: - b3: float = {{.*}}, int = {{.*}}, count = 1 |
| 197 |
|
| 198 |
b4: |
| 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 |
| 204 |
|
| 205 |
b5: |
| 206 |
call void @llvm.pseudoprobe(i64 -907520326213521421, i64 5, i32 0, i64 -1) |
| 207 |
br label %b7 |
| 208 |
; CHECK: edge %b5 -> %b7 probability is 0x80000000 / 0x80000000 = 100.00% |
| 209 |
; CHECK2: - b5: float = {{.*}}, int = {{.*}}, count = 5992 |
| 210 |
|
| 211 |
b6: |
| 212 |
call void @llvm.pseudoprobe(i64 -907520326213521421, i64 6, i32 0, i64 -1) |
| 213 |
br label %b8 |
| 214 |
; CHECK: edge %b6 -> %b8 probability is 0x80000000 / 0x80000000 = 100.00% |
| 215 |
; CHECK2: - b6: float = {{.*}}, int = {{.*}}, count = 0 |
| 216 |
|
| 217 |
b7: |
| 218 |
call void @llvm.pseudoprobe(i64 -907520326213521421, i64 7, i32 0, i64 -1) |
| 219 |
br label %b8 |
| 220 |
; CHECK: edge %b7 -> %b8 probability is 0x80000000 / 0x80000000 = 100.00% |
| 221 |
; CHECK2: - b7: float = {{.*}}, int = {{.*}}, count = 5992 |
| 222 |
|
| 223 |
b8: |
| 224 |
call void @llvm.pseudoprobe(i64 -907520326213521421, i64 8, i32 0, i64 -1) |
| 225 |
br label %b9 |
| 226 |
; CHECK: edge %b8 -> %b9 probability is 0x80000000 / 0x80000000 = 100.00% |
| 227 |
; CHECK2: - b8: float = {{.*}}, int = {{.*}}, count = 5992 |
| 228 |
|
| 229 |
b9: |
| 230 |
call void @llvm.pseudoprobe(i64 -907520326213521421, i64 9, i32 0, i64 -1) |
| 231 |
ret i32 %0 |
| 232 |
} |
| 233 |
; CHECK2: - b9: float = {{.*}}, int = {{.*}}, count = 5993 |
| 234 |
|
| 235 |
|
| 236 |
declare void @llvm.pseudoprobe(i64, i64, i32, i64) #1 |
| 237 |
|
| 238 |
attributes #0 = { noinline nounwind uwtable "use-sample-profile"} |
| 239 |
attributes #1 = { nounwind } |
| 240 |
|
| 241 |
!llvm.pseudo_probe_desc = !{!6, !7, !8, !9} |
| 242 |
|
| 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} |