@@ -232,6 +232,46 @@ loop_exit:
232
232
ret void
233
233
}
234
234
235
+ ; BFI_BEFORE-LABEL: block-frequency-info: func6_inaccurate_branch_weight
236
+ ; BFI_BEFORE: - entry: {{.*}} count = 1024
237
+ ; BFI_BEFORE: - loop_header: {{.*}} count = 2047
238
+ ; BFI_BEFORE: - loop_body: {{.*}} count = 1023
239
+ ; BFI_BEFORE: - loop_exit: {{.*}} count = 1024
240
+
241
+ ; BFI_AFTER-LABEL: block-frequency-info: func6_inaccurate_branch_weight
242
+ ; BFI_AFTER: - entry: {{.*}} count = 1024
243
+ ; BFI_AFTER: - loop_body: {{.*}} count = 4294967296
244
+ ; BFI_AFTER: - loop_exit: {{.*}} count = 1024
245
+
246
+ ; IR-LABEL: define void @func6_inaccurate_branch_weight(
247
+ ; IR: entry:
248
+ ; IR: br label %loop_body
249
+ ; IR: loop_body:
250
+ ; IR: br i1 %cmp, label %loop_body, label %loop_exit, !prof [[PROF_FUNC6_0:![0-9]+]]
251
+ ; IR: loop_exit:
252
+ ; IR: ret void
253
+
254
+ ; Branch weight from sample-based PGO may be inaccurate due to sampling.
255
+ ; Count for loop_body in following case should be not less than loop_exit.
256
+ ; However this may not hold for Sample-based PGO.
257
+ define void @func6_inaccurate_branch_weight () !prof !3 {
258
+ entry:
259
+ br label %loop_header
260
+
261
+ loop_header:
262
+ %i = phi i32 [0 , %entry ], [%i_inc , %loop_body ]
263
+ %cmp = icmp slt i32 %i , 2
264
+ br i1 %cmp , label %loop_body , label %loop_exit , !prof !9
265
+
266
+ loop_body:
267
+ store volatile i32 %i , ptr @g , align 4
268
+ %i_inc = add i32 %i , 1
269
+ br label %loop_header
270
+
271
+ loop_exit:
272
+ ret void
273
+ }
274
+
235
275
!0 = !{!"function_entry_count" , i64 1 }
236
276
!1 = !{!"branch_weights" , i32 1000 , i32 1 }
237
277
!2 = !{!"branch_weights" , i32 3000 , i32 1000 }
@@ -241,6 +281,7 @@ loop_exit:
241
281
!6 = !{!"branch_weights" , i32 0 , i32 1 }
242
282
!7 = !{!"branch_weights" , i32 1 , i32 0 }
243
283
!8 = !{!"branch_weights" , i32 0 , i32 0 }
284
+ !9 = !{!"branch_weights" , i32 1023 , i32 1024 }
244
285
245
286
; IR: [[PROF_FUNC0_0]] = !{!"branch_weights", i32 2000, i32 1000}
246
287
; IR: [[PROF_FUNC0_1]] = !{!"branch_weights", i32 999, i32 1}
@@ -251,3 +292,4 @@ loop_exit:
251
292
; IR: [[PROF_FUNC3_0]] = !{!"branch_weights", i32 0, i32 1}
252
293
; IR: [[PROF_FUNC4_0]] = !{!"branch_weights", i32 1, i32 0}
253
294
; IR: [[PROF_FUNC5_0]] = !{!"branch_weights", i32 0, i32 0}
295
+ ; IR: [[PROF_FUNC6_0]] = !{!"branch_weights", i32 -1, i32 1024}
0 commit comments