-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SimplifyCFG] Increase budget for FoldTwoEntryPHINode() if the branch is unpredictable. #98495
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fe7c50a
[SimplifyCFG] Increase budget for FoldTwoEntryPHINode() if the branch
tianqingw 645ba1f
Add debug log.
tianqingw da55feb
Returns InstructionCost for getBranchMispredictPenalty().
tianqingw b008d5f
clang-format.
tianqingw fa967f8
Canonicalize the test.
tianqingw 7a8e32b
Add "speculate-unpredictables" SimplifyCFGOptions.
tianqingw 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
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
100 changes: 100 additions & 0 deletions
100
llvm/test/Transforms/SimplifyCFG/two-entry-phi-fold-unpredictable.ll
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,100 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 5 | ||
| ; Two-entry phi nodes with unpredictable conditions may get increased budget for folding. | ||
| ; RUN: opt < %s -S -passes=simplifycfg | FileCheck --check-prefix=CHECK-NOFOLD %s | ||
| ; RUN: opt < %s -S -passes='simplifycfg<speculate-unpredictables>' | FileCheck --check-prefix=CHECK-NOFOLD %s | ||
| ; RUN: opt -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 < %s -S -passes=simplifycfg | FileCheck --check-prefix=CHECK-NOFOLD %s | ||
| ; RUN: opt -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 < %s -S -passes='simplifycfg<speculate-unpredictables>' | FileCheck --check-prefix=CHECK-FOLD %s | ||
|
|
||
| define { <2 x float>, <2 x float> } @foo(float %arg, <2 x float> %arg1, <2 x float> %arg2) #0 { | ||
| ; CHECK-NOFOLD-LABEL: define { <2 x float>, <2 x float> } @foo( | ||
| ; CHECK-NOFOLD-SAME: float [[ARG:%.*]], <2 x float> [[ARG1:%.*]], <2 x float> [[ARG2:%.*]]) #[[ATTR0:[0-9]+]] { | ||
| ; CHECK-NOFOLD-NEXT: [[BB:.*]]: | ||
| ; CHECK-NOFOLD-NEXT: [[I:%.*]] = fcmp fast ogt float [[ARG]], 0x3F747AE140000000 | ||
| ; CHECK-NOFOLD-NEXT: br i1 [[I]], label %[[BB3:.*]], label %[[BB20:.*]], !unpredictable [[META0:![0-9]+]] | ||
| ; CHECK-NOFOLD: [[BB3]]: | ||
| ; CHECK-NOFOLD-NEXT: [[I4:%.*]] = extractelement <2 x float> [[ARG1]], i64 0 | ||
| ; CHECK-NOFOLD-NEXT: [[I5:%.*]] = fmul fast float [[I4]], [[I4]] | ||
| ; CHECK-NOFOLD-NEXT: [[I6:%.*]] = extractelement <2 x float> [[ARG1]], i64 1 | ||
| ; CHECK-NOFOLD-NEXT: [[I7:%.*]] = fmul fast float [[I6]], [[I6]] | ||
| ; CHECK-NOFOLD-NEXT: [[I8:%.*]] = fadd fast float [[I7]], [[I5]] | ||
| ; CHECK-NOFOLD-NEXT: [[I9:%.*]] = extractelement <2 x float> [[ARG2]], i64 0 | ||
| ; CHECK-NOFOLD-NEXT: [[I10:%.*]] = fmul fast float [[I9]], [[I9]] | ||
| ; CHECK-NOFOLD-NEXT: [[I11:%.*]] = fadd fast float [[I8]], [[I10]] | ||
| ; CHECK-NOFOLD-NEXT: [[I12:%.*]] = tail call fast noundef float @llvm.sqrt.f32(float [[I11]]) | ||
| ; CHECK-NOFOLD-NEXT: [[I13:%.*]] = fdiv fast float 0x3FEFD70A40000000, [[I12]] | ||
| ; CHECK-NOFOLD-NEXT: [[I14:%.*]] = fmul fast float [[I13]], [[I4]] | ||
| ; CHECK-NOFOLD-NEXT: [[I15:%.*]] = insertelement <2 x float> poison, float [[I14]], i64 0 | ||
| ; CHECK-NOFOLD-NEXT: [[I16:%.*]] = fmul fast float [[I13]], [[I6]] | ||
| ; CHECK-NOFOLD-NEXT: [[I17:%.*]] = insertelement <2 x float> [[I15]], float [[I16]], i64 1 | ||
| ; CHECK-NOFOLD-NEXT: [[I18:%.*]] = fmul fast float [[I13]], [[I9]] | ||
| ; CHECK-NOFOLD-NEXT: [[I19:%.*]] = insertelement <2 x float> [[ARG2]], float [[I18]], i64 0 | ||
| ; CHECK-NOFOLD-NEXT: br label %[[BB20]] | ||
| ; CHECK-NOFOLD: [[BB20]]: | ||
| ; CHECK-NOFOLD-NEXT: [[I21:%.*]] = phi nsz <2 x float> [ [[I17]], %[[BB3]] ], [ zeroinitializer, %[[BB]] ] | ||
| ; CHECK-NOFOLD-NEXT: [[I22:%.*]] = phi nsz <2 x float> [ [[I19]], %[[BB3]] ], [ zeroinitializer, %[[BB]] ] | ||
| ; CHECK-NOFOLD-NEXT: [[I23:%.*]] = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> [[I21]], 0 | ||
| ; CHECK-NOFOLD-NEXT: [[I24:%.*]] = insertvalue { <2 x float>, <2 x float> } [[I23]], <2 x float> [[I22]], 1 | ||
| ; CHECK-NOFOLD-NEXT: ret { <2 x float>, <2 x float> } [[I24]] | ||
| ; | ||
| ; CHECK-FOLD-LABEL: define { <2 x float>, <2 x float> } @foo( | ||
| ; CHECK-FOLD-SAME: float [[ARG:%.*]], <2 x float> [[ARG1:%.*]], <2 x float> [[ARG2:%.*]]) #[[ATTR0:[0-9]+]] { | ||
| ; CHECK-FOLD-NEXT: [[BB:.*:]] | ||
| ; CHECK-FOLD-NEXT: [[I:%.*]] = fcmp fast ogt float [[ARG]], 0x3F747AE140000000 | ||
| ; CHECK-FOLD-NEXT: [[I4:%.*]] = extractelement <2 x float> [[ARG1]], i64 0 | ||
| ; CHECK-FOLD-NEXT: [[I5:%.*]] = fmul fast float [[I4]], [[I4]] | ||
| ; CHECK-FOLD-NEXT: [[I6:%.*]] = extractelement <2 x float> [[ARG1]], i64 1 | ||
| ; CHECK-FOLD-NEXT: [[I7:%.*]] = fmul fast float [[I6]], [[I6]] | ||
| ; CHECK-FOLD-NEXT: [[I8:%.*]] = fadd fast float [[I7]], [[I5]] | ||
| ; CHECK-FOLD-NEXT: [[I9:%.*]] = extractelement <2 x float> [[ARG2]], i64 0 | ||
| ; CHECK-FOLD-NEXT: [[I10:%.*]] = fmul fast float [[I9]], [[I9]] | ||
| ; CHECK-FOLD-NEXT: [[I11:%.*]] = fadd fast float [[I8]], [[I10]] | ||
| ; CHECK-FOLD-NEXT: [[I12:%.*]] = tail call fast float @llvm.sqrt.f32(float [[I11]]) | ||
| ; CHECK-FOLD-NEXT: [[I13:%.*]] = fdiv fast float 0x3FEFD70A40000000, [[I12]] | ||
| ; CHECK-FOLD-NEXT: [[I14:%.*]] = fmul fast float [[I13]], [[I4]] | ||
| ; CHECK-FOLD-NEXT: [[I15:%.*]] = insertelement <2 x float> poison, float [[I14]], i64 0 | ||
| ; CHECK-FOLD-NEXT: [[I16:%.*]] = fmul fast float [[I13]], [[I6]] | ||
| ; CHECK-FOLD-NEXT: [[I17:%.*]] = insertelement <2 x float> [[I15]], float [[I16]], i64 1 | ||
| ; CHECK-FOLD-NEXT: [[I18:%.*]] = fmul fast float [[I13]], [[I9]] | ||
| ; CHECK-FOLD-NEXT: [[I19:%.*]] = insertelement <2 x float> [[ARG2]], float [[I18]], i64 0 | ||
| ; CHECK-FOLD-NEXT: [[I21:%.*]] = select nsz i1 [[I]], <2 x float> [[I17]], <2 x float> zeroinitializer, !unpredictable [[META0:![0-9]+]] | ||
| ; CHECK-FOLD-NEXT: [[I22:%.*]] = select nsz i1 [[I]], <2 x float> [[I19]], <2 x float> zeroinitializer, !unpredictable [[META0]] | ||
| ; CHECK-FOLD-NEXT: [[I23:%.*]] = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> [[I21]], 0 | ||
| ; CHECK-FOLD-NEXT: [[I24:%.*]] = insertvalue { <2 x float>, <2 x float> } [[I23]], <2 x float> [[I22]], 1 | ||
| ; CHECK-FOLD-NEXT: ret { <2 x float>, <2 x float> } [[I24]] | ||
| ; | ||
| bb: | ||
| %i = fcmp fast ogt float %arg, 0x3F747AE140000000 | ||
| br i1 %i, label %bb3, label %bb20, !unpredictable !0 | ||
|
|
||
| bb3: ; preds = %bb | ||
| %i4 = extractelement <2 x float> %arg1, i64 0 | ||
| %i5 = fmul fast float %i4, %i4 | ||
| %i6 = extractelement <2 x float> %arg1, i64 1 | ||
| %i7 = fmul fast float %i6, %i6 | ||
| %i8 = fadd fast float %i7, %i5 | ||
| %i9 = extractelement <2 x float> %arg2, i64 0 | ||
| %i10 = fmul fast float %i9, %i9 | ||
| %i11 = fadd fast float %i8, %i10 | ||
| %i12 = tail call fast noundef float @llvm.sqrt.f32(float %i11) | ||
| %i13 = fdiv fast float 0x3FEFD70A40000000, %i12 | ||
| %i14 = fmul fast float %i13, %i4 | ||
| %i15 = insertelement <2 x float> poison, float %i14, i64 0 | ||
| %i16 = fmul fast float %i13, %i6 | ||
| %i17 = insertelement <2 x float> %i15, float %i16, i64 1 | ||
| %i18 = fmul fast float %i13, %i9 | ||
| %i19 = insertelement <2 x float> %arg2, float %i18, i64 0 | ||
| br label %bb20 | ||
|
|
||
| bb20: ; preds = %bb3, %bb | ||
| %i21 = phi nsz <2 x float> [ %i17, %bb3 ], [ zeroinitializer, %bb ] | ||
| %i22 = phi nsz <2 x float> [ %i19, %bb3 ], [ zeroinitializer, %bb ] | ||
| %i23 = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> %i21, 0 | ||
| %i24 = insertvalue { <2 x float>, <2 x float> } %i23, <2 x float> %i22, 1 | ||
| ret { <2 x float>, <2 x float> } %i24 | ||
| } | ||
|
|
||
| declare float @llvm.sqrt.f32(float) | ||
|
|
||
| attributes #0 = { nounwind } | ||
|
|
||
| !0 = !{} |
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.
How did you arrive at the value 14? Why is the TODO a TODO and not implemented in this PR?