[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
Fri Apr 11 11:15:36 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:

Hey, so I did 9b959746c3125f3f8727158cb26151b666ff6772, 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.

https://github.com/llvm/llvm-project/pull/135277


More information about the llvm-commits mailing list