Skip to content

Commit 38f5596

Browse files
authored
[LoopRotate] Add test to track update for inaccurate branch weight (#86495)
Branch weight from sample-based PGO may be not inaccurate due to sampling. This test tracks such case where updateBranchWeights wraps unsigned.
1 parent b7ac8fd commit 38f5596

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

llvm/test/Transforms/LoopRotate/update-branch-weights.ll

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,46 @@ loop_exit:
232232
ret void
233233
}
234234

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+
235275
!0 = !{!"function_entry_count", i64 1}
236276
!1 = !{!"branch_weights", i32 1000, i32 1}
237277
!2 = !{!"branch_weights", i32 3000, i32 1000}
@@ -241,6 +281,7 @@ loop_exit:
241281
!6 = !{!"branch_weights", i32 0, i32 1}
242282
!7 = !{!"branch_weights", i32 1, i32 0}
243283
!8 = !{!"branch_weights", i32 0, i32 0}
284+
!9 = !{!"branch_weights", i32 1023, i32 1024}
244285

245286
; IR: [[PROF_FUNC0_0]] = !{!"branch_weights", i32 2000, i32 1000}
246287
; IR: [[PROF_FUNC0_1]] = !{!"branch_weights", i32 999, i32 1}
@@ -251,3 +292,4 @@ loop_exit:
251292
; IR: [[PROF_FUNC3_0]] = !{!"branch_weights", i32 0, i32 1}
252293
; IR: [[PROF_FUNC4_0]] = !{!"branch_weights", i32 1, i32 0}
253294
; IR: [[PROF_FUNC5_0]] = !{!"branch_weights", i32 0, i32 0}
295+
; IR: [[PROF_FUNC6_0]] = !{!"branch_weights", i32 -1, i32 1024}

0 commit comments

Comments
 (0)