-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[CodeGen] Preserve branch weights from PGO profile during instruction selection at -O0 #161620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c55f594
Calculate edge weights in MIR if PGO is available in O0
grigorypas 6e4ebda
Register analysis only if PGO is present
grigorypas 0af0751
Keep only pgo-kind option
grigorypas 67050dd
Turn on PGO passes only if PGO enums are set to use
grigorypas 293b095
Addressed comments
grigorypas a4773d9
Changed PGOOptions check for CSPGO
grigorypas b870ddd
Changed function name
grigorypas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
; RUN: llc -mtriple=x86_64-- -O0 -debug-pass=Structure %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=PASSES | ||
; RUN: llc -mtriple=x86_64-- -O0 -debug-only=branch-prob %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=BRANCH_PROB | ||
; RUN: llc -mtriple=x86_64-- -O0 -stop-after=finalize-isel %s -o - | FileCheck %s --check-prefix=MIR | ||
|
||
; REQUIRES: asserts | ||
|
||
; This test verifies that PGO profile information (branch weights) is preserved | ||
; during instruction selection at -O0. | ||
|
||
; Test function with explicit branch weights from PGO. | ||
define i32 @test_pgo_preservation(i32 %x) !prof !15 { | ||
entry: | ||
%cmp = icmp sgt i32 %x, 10 | ||
; This branch has bias: 97 taken vs 3 not taken | ||
br i1 %cmp, label %if.then, label %if.else, !prof !16 | ||
|
||
if.then: | ||
; Hot path - should have high frequency | ||
%add = add nsw i32 %x, 100 | ||
br label %if.end | ||
|
||
if.else: | ||
; Cold path - should have low frequency | ||
%sub = sub nsw i32 %x, 50 | ||
br label %if.end | ||
|
||
if.end: | ||
%result = phi i32 [ %add, %if.then ], [ %sub, %if.else ] | ||
ret i32 %result | ||
} | ||
|
||
; Profile metadata with branch weights 97:3. | ||
!15 = !{!"function_entry_count", i64 100} | ||
!16 = !{!"branch_weights", i32 97, i32 3} | ||
|
||
; Verify that Branch Probability Analysis runs at O0. | ||
; PASSES: Branch Probability Analysis | ||
|
||
; Verify that the branch probabilities reflect the exact profile data. | ||
; BRANCH_PROB: ---- Branch Probability Info : test_pgo_preservation ---- | ||
; BRANCH_PROB: set edge entry -> 0 successor probability to {{.*}} = 97.00% | ||
; BRANCH_PROB: set edge entry -> 1 successor probability to {{.*}} = 3.00% | ||
|
||
; Verify that machine IR preserves the branch probabilities from profile data | ||
; MIR: bb.0.entry: | ||
; MIR-NEXT: successors: %bb.{{[0-9]+}}({{0x03d70a3d|0x7c28f5c3}}), %bb.{{[0-9]+}}({{0x7c28f5c3|0x03d70a3d}}) | ||
; The two successor probability values should be: | ||
; - 0x7c28f5c3: approximately 97% (high probability successor) | ||
; - 0x03d70a3d: approximately 3% (low probability successor) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can add extra check for PGO (
Selector->TM.getPGOOption()
) and only do the analysis when PGO is used.