-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CodeGen][NPM] Update BranchFolderLegacy make tail merge configurable via flag #135277
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
base: main
Are you sure you want to change the base?
Conversation
…option to enable tail merge Signed-off-by: Mikhail R. Gadelha <[email protected]>
Signed-off-by: Mikhail R. Gadelha <[email protected]>
Signed-off-by: Mikhail R. Gadelha <[email protected]>
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.
@arsenm this is a tentative patch do address your comments.
I do have a couple of questions:
llvm/lib/CodeGen/BranchFolding.cpp
Outdated
@@ -152,7 +162,8 @@ bool BranchFolderLegacy::runOnMachineFunction(MachineFunction &MF) { | |||
// TailMerge can create jump into if branches that make CFG irreducible for | |||
// HW that requires structurized CFG. | |||
bool EnableTailMerge = !MF.getTarget().requiresStructuredCFG() && | |||
PassConfig->getEnableTailMerge(); | |||
PassConfig->getEnableTailMerge() && |
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.
This global state should be moved to only change the pass parameter
Do you mean I should remove the PassConfig->getEnableTailMerge()
?
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.
Yes, it can be passed as the EnableTailMerge
parameter when TargetPassConfig creates this pass instance (where currently this is done through its ID).
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.
Hey, so I did 9b95974, but I'm getting a weird error: when the branch folding pass runs now, I get that the pre-conditions are not valid:
MachineFunctionProperties required by Control Flow Optimizer pass are not met by function RWBufferStore_Vec4_I32.
Required properties: NoPHIs
Current properties: IsSSA, TracksLiveness, Legalized, Selected
This seems to only happen because of this change:
// Branch folding must be run after regalloc and prolog/epilog insertion.
- addPass(&BranchFolderPassID);
+ addPass(createBranchFolderPass(getEnableTailMerge()));
The calling addPass
with the BranchFolderPassID
, it doesn't seem to be added to the list of passes because char BranchFolderLegacy::ID = 0
, whereas when we call createBranchFolderPass
, the pass is added and fails.
Maybe I'm missing some detail here, but the pass doesn't seem to run at all before my changes.
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.
In the failing tests, the branch folding pass is disabled here:
disablePass(&BranchFolderPassID); |
So by calling createBranchFolderPass
, we don't check the disabled passed
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.
This also seems to bypass the -disable-branch-fold
.
Any suggestions on how to proceed?
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 the function properties error is from somewhere else. Most passes probably are not appropriately reporting cleared properties
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.
What test hit the property error? I think SPIRV needs to cear NoPHIs property after its selection. It's bypassing the usual place it's cleared (though I'm not sure why it's cleared here)
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.
All tests are passing with the latest version of this PR
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.
Is this avoided after the new version of #136327?
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.
This piece of code is no longer part of the PR.
public: | ||
static char ID; | ||
|
||
explicit BranchFolderLegacy() : MachineFunctionPass(ID) {} | ||
explicit BranchFolderLegacy(bool EnableTailMerge = true) | ||
: MachineFunctionPass(ID), EnableTailMerge(EnableTailMerge) {} |
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.
That added the initial port to the new pm. This is now changing the pass arguments in the old PM, without the matching new PM change
Are you talking about the default argument? I see that BranchFolderPass
already takes a bool EnableTailMerge
:
BranchFolderPass(bool EnableTailMerge) : EnableTailMerge(EnableTailMerge) {} |
Signed-off-by: Mikhail R. Gadelha <[email protected]>
Signed-off-by: Mikhail R. Gadelha <[email protected]>
Signed-off-by: Mikhail R. Gadelha <[email protected]>
Signed-off-by: Mikhail R. Gadelha <[email protected]>
Signed-off-by: Mikhail R. Gadelha <[email protected]>
This reverts commit f2dd02c.
…nter Signed-off-by: Mikhail R. Gadelha <[email protected]>
ping |
IdentifyingPassPtr TargetID = getPassSubstitution(PassID); | ||
if (!overridePass(PassID, TargetID).isValid()) | ||
return; |
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.
Shouldn't need to touch the override infrastructure?
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.
Sorry, I don't get it... What do you mean?
I had to add this to check if the pass was disabled. It's a copy-and-paste from the addPass(AnalysisID PassID)
method.
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.
Yes, that's the problem. You shouldn't have to do anything like this
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've replaced this check with a isPassSubstitutedOrOverridden
check, similar to how it's done for createPrologEpilogInserterPass
. Does this address your comment?
There should be no PHIs after selection, as OpPhi is used instead. This hopefully avoids errors in #135277.
Signed-off-by: Mikhail R. Gadelha <[email protected]>
Signed-off-by: Mikhail R. Gadelha <[email protected]>
Signed-off-by: Mikhail R. Gadelha <[email protected]>
✅ With the latest revision this PR passed the C/C++ code formatter. |
Signed-off-by: Mikhail R. Gadelha <[email protected]>
ping |
There should be no PHIs after selection, as OpPhi is used instead. This hopefully avoids errors in #135277.
There should be no PHIs after selection, as OpPhi is used instead. This hopefully avoids errors in #135277.
There should be no PHIs after selection, as OpPhi is used instead. This hopefully avoids errors in #135277.
ping |
@@ -123,9 +124,6 @@ INITIALIZE_PASS(BranchFolderLegacy, DEBUG_TYPE, "Control Flow Optimizer", false, | |||
PreservedAnalyses BranchFolderPass::run(MachineFunction &MF, | |||
MachineFunctionAnalysisManager &MFAM) { | |||
MFPropsModifier _(*this, MF); | |||
bool EnableTailMerge = |
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.
Since you're removing it here, the NPM require the flag requiresStructuredCFG()
to be incorporated here.
There should be no PHIs after selection, as OpPhi is used instead. This hopefully avoids errors in llvm#135277.
There should be no PHIs after selection, as OpPhi is used instead. This hopefully avoids errors in llvm#135277.
There should be no PHIs after selection, as OpPhi is used instead. This hopefully avoids errors in llvm#135277.
There should be no PHIs after selection, as OpPhi is used instead. This hopefully avoids errors in llvm#135277.
This patch adds support for configuring the BranchFolderPass with or without tail merging.