[llvm] [LV] Transform to handle exits in the scalar loop (PR #148626)
Gaƫtan Bossu via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 28 08:36:04 PST 2025
================
@@ -3558,42 +3561,45 @@ void VPlanTransforms::handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB,
// block if CondToEarlyExit.
VPValue *IsEarlyExitTaken =
Builder.createNaryOp(VPInstruction::AnyOf, {CondToEarlyExit});
- VPBasicBlock *NewMiddle = Plan.createVPBasicBlock("middle.split");
- VPBasicBlock *VectorEarlyExitVPBB =
- Plan.createVPBasicBlock("vector.early.exit");
- VPBlockUtils::insertOnEdge(LatchVPBB, MiddleVPBB, NewMiddle);
- VPBlockUtils::connectBlocks(NewMiddle, VectorEarlyExitVPBB);
- NewMiddle->swapSuccessors();
-
- VPBlockUtils::connectBlocks(VectorEarlyExitVPBB, EarlyExitVPBB);
-
- // Update the exit phis in the early exit block.
- VPBuilder MiddleBuilder(NewMiddle);
- VPBuilder EarlyExitB(VectorEarlyExitVPBB);
- for (VPRecipeBase &R : EarlyExitVPBB->phis()) {
- auto *ExitIRI = cast<VPIRPhi>(&R);
- // Early exit operand should always be last, i.e., 0 if EarlyExitVPBB has
- // a single predecessor and 1 if it has two.
- unsigned EarlyExitIdx = ExitIRI->getNumOperands() - 1;
- if (ExitIRI->getNumOperands() != 1) {
- // The first of two operands corresponds to the latch exit, via MiddleVPBB
- // predecessor. Extract its last lane.
- ExitIRI->extractLastLaneOfFirstOperand(MiddleBuilder);
- }
+ if (!Plan.shouldEarlyExitContinueInScalarLoop()) {
----------------
gbossu wrote:
I think it would be worth updating `llvm/docs/Vectorizers.rst` now that there is a new strategy to handle EE loops.
Given that this new strategy is currently toggled using `cl::opt<bool> HandleEarlyExitsInScalarTail`, do you plan to make it the default eventually or will there be a new TTI hook?
https://github.com/llvm/llvm-project/pull/148626
More information about the llvm-commits
mailing list