[llvm] [VPlan] Move initial skeleton construction earlier (NFC). (PR #150848)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 3 09:27:10 PDT 2025
================
@@ -488,12 +488,46 @@ void VPlanTransforms::prepareForVectorization(
addCanonicalIVRecipes(Plan, HeaderVPBB, LatchVPBB, InductionTy, IVDL);
- [[maybe_unused]] bool HandledUncountableEarlyExit = false;
+ // Create SCEV and VPValue for the trip count.
+ // We use the symbolic max backedge-taken-count, which works also when
+ // vectorizing loops with uncountable early exits.
+ const SCEV *BackedgeTakenCountSCEV = PSE.getSymbolicMaxBackedgeTakenCount();
+ assert(!isa<SCEVCouldNotCompute>(BackedgeTakenCountSCEV) &&
+ "Invalid backedge-taken count");
+ ScalarEvolution &SE = *PSE.getSE();
+ const SCEV *TripCount = SE.getTripCountFromExitCount(BackedgeTakenCountSCEV,
+ InductionTy, TheLoop);
+ Plan.setTripCount(
+ vputils::getOrCreateVPValueForSCEVExpr(Plan, TripCount, SE));
+
+ VPBasicBlock *ScalarPH = Plan.createVPBasicBlock("scalar.ph");
+ VPBlockUtils::connectBlocks(ScalarPH, Plan.getScalarHeader());
+
+ // The connection order corresponds to the operands of the conditional branch,
+ // with the middle block already connected to the exit block.
+ VPBlockUtils::connectBlocks(MiddleVPBB, ScalarPH);
+ // Also connect the entry block to the scalar preheader.
+ // TODO: Also introduce a branch recipe together with the minimum trip count
+ // check.
+ VPBlockUtils::connectBlocks(Plan.getEntry(), ScalarPH);
+ Plan.getEntry()->swapSuccessors();
+}
+
+void VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(
----------------
ayalz wrote:
Splitting middle block is one part of handling certain early exits.
```suggestion
void VPlanTransforms::handleEarlyExits(
```
https://github.com/llvm/llvm-project/pull/150848
More information about the llvm-commits
mailing list