[llvm] [CodeGen][NPM] Update BranchFolderLegacy make tail merge configurable via flag (PR #135277)
Mikhail R. Gadelha via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 15 11:01:48 PDT 2025
================
@@ -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() &&
----------------
mikhailramalho wrote:
I tried the solution in the past few days but there is a problem, here's the new `addPass`:
```
AnalysisID TargetPassConfig::addPass(IdentifyingPassPtr PassPtr) {
AnalysisID PassID = PassPtr.isInstance() ? PassPtr.getInstance()->getPassID()
: PassPtr.getID();
IdentifyingPassPtr TargetID = getPassSubstitution(PassID);
IdentifyingPassPtr FinalPtr = overridePass(PassID, TargetID);
if (!FinalPtr.isValid())
return nullptr;
Pass *P;
if (FinalPtr.isInstance())
P = FinalPtr.getInstance();
else {
P = Pass::createPass(FinalPtr.getID()); // <--- it creates the pass again
if (!P)
llvm_unreachable("Pass ID not registered");
}
AnalysisID FinalID = P->getPassID();
addPass(P); // Ends the lifetime of P.
return FinalID;
}
```
The issue lies when calling `Pass::createPass` with `IdentifyingPassPtr`, so even when we call `addPass(IdentifyingPassPtr(createBranchFolderPass(getEnableTailMerge())));` and create the Pass with the value from `getEnableTailMerge()`, it's ignored and created again with the default constructor for the pass (see comment on the code).
The problem with this approach (on top of calling the constructor twice) is that since we removed `PassConfig->getEnableTailMerge()` from `runOnMachineFunction`, it will run with whatever we set `BranchFolderLegacy::EnableTailMerge` to be by default, ignoring what's passed via `createBranchFolderPass`
https://github.com/llvm/llvm-project/pull/135277
More information about the llvm-commits
mailing list