[llvm] [VPlan] Hook IR blocks into VPlan during skeleton creation (NFC) (PR #114292)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 3 16:34:20 PST 2024
================
@@ -2428,6 +2428,32 @@ InnerLoopVectorizer::getOrCreateVectorTripCount(BasicBlock *InsertBlock) {
return VectorTripCount;
}
+/// Helper to connect both the vector and scalar preheaders to the Plan's
+/// entry. This is used when adjusting \p Plan during skeleton
+/// creation, i.e. adjusting the plan after introducing an initial runtime
+/// check.
+/// TODO: Connect scalar preheader during initial VPlan construction.
+static void connectScalarPreheaderAsBypassInVPlan(VPlan &Plan) {
----------------
ayalz wrote:
This corresponds to introducing **the first check** into VPlan. This check is fused into the Entry block, which has a single successor (the vector loop preheader), by replacing its terminator with a conditional branch, whose taken destination is to be the first successor (the scalar loop preheader).
Below corresponds to introducing **another check** into VPlan. A previous (last) check has both scalar and vector loop preheaders as its successors. A new VPBB is created to host the additional check, placed between this previous check and vector loop preheader.
A new VPBB can also be created for the first check, to align the two cases, and be merged subsequently with its predecessor.
Would it be clearer to fold the above into the below, and have `introduceCheckBlockInVPlan()` also handle the first check, as in:
```
static void introduceCheckBlockInVPlan(VPlan &Plan, BasicBlock *CheckBB) {
VPBlockBase *ScalarPH = Plan.getScalarPreheader();
VPBlockBase *VectorPH = Plan.getVectorPreheader();
VPBlockBase *PreVectorPH = VectorPH->getSinglePredecessor();
if (PreVectorPH->getNumSuccessors() != 1) {
assert(PreVectorPH->getNumSuccessors() == 2 && "Expected 2 successors");
assert(PreVectorPH->getSuccessors()[0] == ScalarPH && "Unexpected successor");
VPIRBasicBlock *CheckVPIRBB = VPIRBasicBlock::fromBasicBlock(CheckBB);
VPBlockUtils::insertOnEdge(PreVectorPH, VectorPH, CheckVPIRBB);
PreVectorPH = CheckVPIRBB;
}
VPBlockUtils::connectBlocks(PreVectorPH, ScalarPH);
VPBlockUtils::swapSucceccors(PreVectorPH);
}
```
WDYT?
https://github.com/llvm/llvm-project/pull/114292
More information about the llvm-commits
mailing list