[llvm] [VPlan] Model epilogue skeleton in VPlan by wrapping in VPIRBBs (NFCI). (PR #222312)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 07:14:57 PDT 2026
================
@@ -1461,6 +1429,58 @@ static void insertCheckBlockBeforeVectorLoop(VPlan &Plan,
addIncomingForLastPredecessor(ScalarPH);
}
+void VPlanTransforms::modelGeneratedMainLoopBlocks(
+ VPlan &Plan, VPlan &MainPlan, VPIRBasicBlock *EnteredFrom) {
+ // Map blocks from MainPlan to new, empty VPIRBasicBlocks in Plan, so the
+ // skeleton CFG can be modeled explicitly. MainPlan's entry maps to Plan's
+ // now-disconnected entry, its scalar PH to EnteredFrom, mapped last so it can
+ // be dropped as source below. Blocks without successors have no edges.
+ auto *MainEntry = cast<VPIRBasicBlock>(MainPlan.getEntry());
+ auto *MainScalarPH = cast<VPIRBasicBlock>(MainPlan.getScalarPreheader());
+ SmallVector<VPIRBasicBlock *> BypassBlocks;
+ SmallMapVector<VPIRBasicBlock *, VPIRBasicBlock *, 8> Old2NewVPBB;
+ Old2NewVPBB[MainEntry] = cast<VPIRBasicBlock>(Plan.getEntry());
+ ReversePostOrderTraversal<VPBlockShallowTraversalWrapper<VPBlockBase *>> RPOT(
+ MainEntry);
+ for (VPIRBasicBlock *VPBB : VPBlockUtils::blocksAs<VPIRBasicBlock>(RPOT)) {
+ // Collect bypass blocks (minimum iteration checks, runtime checks).
+ if (VPBB->getNumSuccessors() == 2 &&
+ VPBB->getSuccessors()[0] == MainScalarPH)
+ BypassBlocks.push_back(VPBB);
+ if (VPBB != MainEntry && VPBB != MainScalarPH && VPBB->hasSuccessors())
+ Old2NewVPBB[VPBB] =
+ Plan.createEmptyVPIRBasicBlock(VPBB->getIRBasicBlock());
+ }
+ Old2NewVPBB[MainScalarPH] = EnteredFrom;
+
+ // First, connect the edges from the bypass blocks to the scalar preheader, in
+ // reverse order, to preserve the predecessor order of the generated IR. The
+ // last bypass block branches into Plan and is mirrored below.
+ VPBasicBlock *ScalarPH = Plan.getScalarPreheader();
----------------
artagnon wrote:
```suggestion
VPBasicBlock *EpiScalarPH = Plan.getScalarPreheader();
```
I think we should call it MainPlan and EpiPlan, and not MainPlan and Plan, which is confusing?
https://github.com/llvm/llvm-project/pull/222312
More information about the llvm-commits
mailing list