Skip to content

Commit 2289a5e

Browse files
committed
!fixup address latest comments, thanks
1 parent ce06761 commit 2289a5e

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -491,36 +491,31 @@ void VPlanTransforms::prepareForVectorization(
491491
cast<VPBasicBlock>(LatchVPB), InductionTy, IVDL);
492492

493493
[[maybe_unused]] bool HandledUncountableEarlyExit = false;
494-
// Handle the remaining early exits, either by converting the plan to one only
495-
// exiting via the latch or by disconnecting all early exiting edges and
496-
// requiring a scalar epilogue.
494+
// Disconnect all early exits from the loop leaving it with a single exit from
495+
// the latch. Early exits that are countable are left for a scalar epilog. The
496+
// condition of uncountable early exits (currently at most one is supported)
497+
// is fused into the latch exit, and used to branch from middle block to the
498+
// early exit destination.
497499
for (VPIRBasicBlock *EB : Plan.getExitBlocks()) {
498500
for (VPBlockBase *Pred : to_vector(EB->getPredecessors())) {
499501
if (Pred == MiddleVPBB)
500502
continue;
501-
502503
if (HasUncountableEarlyExit) {
503504
assert(!HandledUncountableEarlyExit &&
504505
"can handle exactly one uncountable early exit");
505-
// Convert VPlans with early exits to a form exiting only via the latch
506-
// here, including adjusting the exit condition of the latch.
507506
handleUncountableEarlyExit(cast<VPBasicBlock>(Pred), EB, Plan,
508507
cast<VPBasicBlock>(HeaderVPB),
509508
cast<VPBasicBlock>(LatchVPB), Range);
510509
HandledUncountableEarlyExit = true;
511-
continue;
512510
}
513511

514-
// Otherwise all early exits must be countable and we require at least one
515-
// iteration in the scalar epilogue. Disconnect all edges to exit blocks
516-
// other than from the middle block.
517512
cast<VPBasicBlock>(Pred)->getTerminator()->eraseFromParent();
518513
VPBlockUtils::disconnectBlocks(Pred, EB);
519514
}
520515
}
521516

522517
assert((!HasUncountableEarlyExit || HandledUncountableEarlyExit) &&
523-
"did not handle uncountable early exit");
518+
"missed an uncountable exit that must be handled");
524519

525520
// Create SCEV and VPValue for the trip count.
526521
// We use the symbolic max backedge-taken-count, which works also when

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,6 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
24622462

24632463
void VPlanTransforms::handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB,
24642464
VPBasicBlock *EarlyExitVPBB,
2465-
24662465
VPlan &Plan,
24672466
VPBasicBlock *HeaderVPBB,
24682467
VPBasicBlock *LatchVPBB,
@@ -2471,13 +2470,13 @@ void VPlanTransforms::handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB,
24712470

24722471
VPBlockBase *MiddleVPBB = LatchVPBB->getSuccessors()[0];
24732472
if (!EarlyExitVPBB->getSinglePredecessor() &&
2474-
EarlyExitVPBB->getPredecessors()[0] != MiddleVPBB) {
2473+
EarlyExitVPBB->getPredecessors()[1] == MiddleVPBB) {
24752474
assert(EarlyExitVPBB->getNumPredecessors() == 2 &&
2476-
EarlyExitVPBB->getPredecessors()[1] == MiddleVPBB &&
2477-
"unsupported earl exit VPBB");
2475+
EarlyExitVPBB->getPredecessors()[0] == EarlyExitingVPBB &&
2476+
"unsupported early exit VPBB");
24782477
// Early exit operand should always be last phi operand. If EarlyExitVPBB
2479-
// has two predecessors and MiddleVPBB isn't the first, swap the operands of
2480-
// the phis.
2478+
// has two predecessors and EarlyExitingVPBB is the first, swap the operands
2479+
// of the phis.
24812480
for (VPRecipeBase &R : EarlyExitVPBB->phis())
24822481
cast<VPIRPhi>(&R)->swapOperands();
24832482
}
@@ -2492,11 +2491,9 @@ void VPlanTransforms::handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB,
24922491
auto *CondToEarlyExit = TrueSucc == EarlyExitVPBB
24932492
? CondOfEarlyExitingVPBB
24942493
: Builder.createNot(CondOfEarlyExitingVPBB);
2495-
EarlyExitingVPBB->getTerminator()->eraseFromParent();
2496-
VPBlockUtils::disconnectBlocks(EarlyExitingVPBB, EarlyExitVPBB);
24972494

24982495
// Split the middle block and have it conditionally branch to the early exit
2499-
// block if EarlyExitTaken.
2496+
// block if CondToEarlyExit.
25002497
VPValue *IsEarlyExitTaken =
25012498
Builder.createNaryOp(VPInstruction::AnyOf, {CondToEarlyExit});
25022499
VPBasicBlock *NewMiddle = Plan.createVPBasicBlock("middle.split");

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct VPlanTransforms {
6969
PredicatedScalarEvolution &PSE,
7070
bool RequiresScalarEpilogueCheck,
7171
bool TailFolded, Loop *TheLoop,
72-
DebugLoc IVDL, bool HandleUncountableExit,
72+
DebugLoc IVDL, bool HasUncountableExit,
7373
VFRange &Range);
7474

7575
/// Replace loops in \p Plan's flat CFG with VPRegionBlocks, turning \p Plan's
@@ -177,9 +177,9 @@ struct VPlanTransforms {
177177
/// Update \p Plan to account for the uncountable early exit from \p
178178
/// EarlyExitingVPBB to \p EarlyExitVPBB by
179179
/// * updating the condition exiting the vector loop to include the early
180-
/// exit conditions
180+
/// exit condition,
181181
/// * splitting the original middle block to branch to the early exit block
182-
/// if taken.
182+
/// conditionally - according to the early exit condition.
183183
static void handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB,
184184
VPBasicBlock *EarlyExitVPBB,
185185
VPlan &Plan, VPBasicBlock *HeaderVPBB,

0 commit comments

Comments
 (0)