Skip to content

Commit d0081f7

Browse files
committed
!fixup address latest comments, thanks
1 parent 26d7348 commit d0081f7

File tree

5 files changed

+31
-28
lines changed

5 files changed

+31
-28
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9417,7 +9417,7 @@ addUsersInExitBlocks(VPlan &Plan,
94179417
ExitIRI->getParent()->getSinglePredecessor() == MiddleVPBB &&
94189418
"exit values from early exits must be fixed when branch to "
94199419
"early-exit is added");
9420-
ExitIRI->extractLastLaneOfOperand(B);
9420+
ExitIRI->extractLastLaneOfFirstOperand(B);
94219421
}
94229422
}
94239423

llvm/lib/Transforms/Vectorize/VPlan.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1161,10 +1161,10 @@ class VPIRInstruction : public VPRecipeBase {
11611161
return true;
11621162
}
11631163

1164-
/// Update the recipes single operand to the last lane of the operand using \p
1165-
/// Builder. Must only be used for single operand VPIRInstructions wrapping a
1166-
/// PHINode.
1167-
void extractLastLaneOfOperand(VPBuilder &Builder);
1164+
/// Update the recipes first operand to the last lane of the operand using \p
1165+
/// Builder. Must only be used for VPIRInstructions with at least one operand
1166+
/// wrapping a PHINode.
1167+
void extractLastLaneOfFirstOperand(VPBuilder &Builder);
11681168
};
11691169

11701170
/// An overlay for VPIRInstructions wrapping PHI nodes enabling convenient use

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,14 @@ std::unique_ptr<VPlan> PlainCFGBuilder::buildPlainCFG(
352352
Plan->getEntry()->setOneSuccessor(getOrCreateVPBB(TheLoop->getHeader()));
353353
Plan->getEntry()->setPlan(&*Plan);
354354

355-
// Add incoming operands for the VPIRInstructions wrapping the exit phis.
355+
// Fix VPlan loop-closed-ssa exit phi's by add incoming operands to the
356+
// VPIRInstructions wrapping them.
356357
for (auto *EB : Plan->getExitBlocks()) {
357-
for (VPRecipeBase &R : *EB) {
358-
auto *PhiR = dyn_cast<VPIRPhi>(&R);
359-
if (!PhiR)
360-
break;
358+
for (VPRecipeBase &R : EB->phis()) {
359+
auto *PhiR = cast<VPIRPhi>(&R);
361360
PHINode &Phi = PhiR->getIRPhi();
361+
assert(PhiR->getNumOperands() == 0 &&
362+
"no phi operands should be added yet");
362363
for (BasicBlock *Pred : predecessors(EB->getIRBasicBlock()))
363364
PhiR->addOperand(
364365
getOrCreateVPOperand(Phi.getIncomingValueForBlock(Pred)));
@@ -477,8 +478,8 @@ void VPlanTransforms::createLoopRegions(VPlan &Plan, Type *InductionTy,
477478
VPBlockUtils::connectBlocks(ScalarPH, Plan.getScalarHeader());
478479
if (!RequiresScalarEpilogueCheck) {
479480
VPBlockUtils::connectBlocks(MiddleVPBB, ScalarPH);
480-
// The exit blocks are dead, remove any recipes to make sure no users remain
481-
// that may pessimize transforms.
481+
// The exit blocks are unreachable, remove their recipes to make sure no
482+
// users remain that may pessimize transforms.
482483
for (auto *EB : Plan.getExitBlocks()) {
483484
for (VPRecipeBase &R : make_early_inc_range(*EB))
484485
R.eraseFromParent();

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,9 @@ InstructionCost VPIRInstruction::computeCost(ElementCount VF,
11371137
return 0;
11381138
}
11391139

1140-
void VPIRInstruction::extractLastLaneOfOperand(VPBuilder &Builder) {
1140+
void VPIRInstruction::extractLastLaneOfFirstOperand(VPBuilder &Builder) {
11411141
assert(isa<PHINode>(getInstruction()) &&
1142-
"can only add exiting operands to phi nodes");
1142+
"can only update exiting operands to phi nodes");
11431143
assert(getNumOperands() > 0 && "must have at least one operand");
11441144
VPValue *Exiting = getOperand(0);
11451145
if (!Exiting->isLiveIn()) {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -2503,23 +2503,26 @@ void VPlanTransforms::handleUncountableEarlyExit(
25032503
// Update the exit phis in the early exit block.
25042504
VPBuilder MiddleBuilder(NewMiddle);
25052505
VPBuilder EarlyExitB(VectorEarlyExitVPBB);
2506-
for (VPRecipeBase &R : *VPEarlyExitBlock->phis()) {
2506+
for (VPRecipeBase &R : VPEarlyExitBlock->phis()) {
25072507
auto *ExitIRI = cast<VPIRPhi>(&R);
2508+
// By default, assume early exit operand is first, e.g., when the two exit
2509+
// blocks are distinct - VPEarlyExitBlock has a single predecessor.
25082510
unsigned EarlyExitIdx = 0;
25092511
if (OrigLoop->getUniqueExitBlock()) {
2510-
// After the transform, the first incoming value is coming from the
2511-
// orignial loop latch, while the second operand is from the early exit.
2512-
// Sawp the phi operands, if the first predecessor in the original IR is
2513-
// not the loop latch.
2512+
// The incoming values currently correspond to the original IR
2513+
// predecessors. After the transform, the first incoming value is coming
2514+
// from the original loop latch, while the second operand is from the
2515+
// early exit. Swap the phi operands, if the first predecessor in the
2516+
// original IR is not the loop latch.
25142517
if (*pred_begin(VPEarlyExitBlock->getIRBasicBlock()) !=
25152518
OrigLoop->getLoopLatch())
25162519
ExitIRI->swapOperands();
25172520

25182521
EarlyExitIdx = 1;
25192522
// If there's a unique exit block, VPEarlyExitBlock has 2 predecessors
2520-
// (MiddleVPBB and NewMiddle). Add the incoming value from MiddleVPBB
2521-
// which is coming from the original latch.
2522-
ExitIRI->extractLastLaneOfOperand(MiddleBuilder);
2523+
// (MiddleVPBB and NewMiddle). Extract the last lane of the incoming value
2524+
// from MiddleVPBB which is coming from the original latch.
2525+
ExitIRI->extractLastLaneOfFirstOperand(MiddleBuilder);
25232526
}
25242527

25252528
VPValue *IncomingFromEarlyExit = ExitIRI->getOperand(EarlyExitIdx);
@@ -2530,15 +2533,14 @@ void VPlanTransforms::handleUncountableEarlyExit(
25302533
// and vector VFs.
25312534
if (!IncomingFromEarlyExit->isLiveIn() &&
25322535
LoopVectorizationPlanner::getDecisionAndClampRange(IsVector, Range)) {
2533-
// Add the incoming value from the early exit.
2536+
// Update the incoming value from the early exit.
25342537
VPValue *FirstActiveLane = EarlyExitB.createNaryOp(
25352538
VPInstruction::FirstActiveLane, {EarlyExitTakenCond}, nullptr,
25362539
"first.active.lane");
2537-
ExitIRI->setOperand(
2538-
EarlyExitIdx,
2539-
EarlyExitB.createNaryOp(Instruction::ExtractElement,
2540-
{IncomingFromEarlyExit, FirstActiveLane},
2541-
nullptr, "early.exit.value"));
2540+
IncomingFromEarlyExit = EarlyExitB.createNaryOp(
2541+
Instruction::ExtractElement, {IncomingFromEarlyExit, FirstActiveLane},
2542+
nullptr, "early.exit.value");
2543+
ExitIRI->setOperand(EarlyExitIdx, IncomingFromEarlyExit);
25422544
}
25432545
}
25442546
MiddleBuilder.createNaryOp(VPInstruction::BranchOnCond, {IsEarlyExitTaken});

0 commit comments

Comments
 (0)