Skip to content

[VPlan] Introduce VPSingleDefRecipe. #77023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8963,16 +8963,17 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
"AnyOf reductions are not allowed for in-loop reductions");

// Collect the chain of "link" recipes for the reduction starting at PhiR.
SetVector<VPRecipeBase *> Worklist;
SetVector<VPSingleDefRecipe *> Worklist;
Worklist.insert(PhiR);
for (unsigned I = 0; I != Worklist.size(); ++I) {
VPRecipeBase *Cur = Worklist[I];
for (VPUser *U : Cur->getVPSingleValue()->users()) {
auto *UserRecipe = dyn_cast<VPRecipeBase>(U);
if (!UserRecipe)
VPSingleDefRecipe *Cur = Worklist[I];
for (VPUser *U : Cur->users()) {
auto *UserRecipe = dyn_cast<VPSingleDefRecipe>(U);
if (!UserRecipe) {
assert(isa<VPLiveOut>(U) &&
"U must either be a VPSingleDef or VPLiveOut");
continue;
assert(UserRecipe->getNumDefinedValues() == 1 &&
"recipes must define exactly one result value");
}
Worklist.insert(UserRecipe);
}
}
Expand All @@ -8982,10 +8983,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
// (PreviousLink) to tell which of the two operands of a Link will remain
// scalar and which will be reduced. For minmax by select(cmp), Link will be
// the select instructions.
VPRecipeBase *PreviousLink = PhiR; // Aka Worklist[0].
for (VPRecipeBase *CurrentLink : Worklist.getArrayRef().drop_front()) {
VPValue *PreviousLinkV = PreviousLink->getVPSingleValue();

VPSingleDefRecipe *PreviousLink = PhiR; // Aka Worklist[0].
for (VPSingleDefRecipe *CurrentLink : Worklist.getArrayRef().drop_front()) {
Instruction *CurrentLinkI = CurrentLink->getUnderlyingInstr();

// Index of the first operand which holds a non-mask vector operand.
Expand All @@ -9000,7 +8999,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
"Expected instruction to be a call to the llvm.fmuladd intrinsic");
assert(((MinVF.isScalar() && isa<VPReplicateRecipe>(CurrentLink)) ||
isa<VPWidenCallRecipe>(CurrentLink)) &&
CurrentLink->getOperand(2) == PreviousLinkV &&
CurrentLink->getOperand(2) == PreviousLink &&
"expected a call where the previous link is the added operand");

// If the instruction is a call to the llvm.fmuladd intrinsic then we
Expand Down Expand Up @@ -9031,15 +9030,15 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
// Note that for non-commutable operands (cmp-selects), the semantics of
// the cmp-select are captured in the recurrence kind.
unsigned VecOpId =
CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLinkV
CurrentLink->getOperand(IndexOfFirstOperand) == PreviousLink
? IndexOfFirstOperand + 1
: IndexOfFirstOperand;
VecOp = CurrentLink->getOperand(VecOpId);
assert(VecOp != PreviousLinkV &&
assert(VecOp != PreviousLink &&
CurrentLink->getOperand(CurrentLink->getNumOperands() - 1 -
(VecOpId - IndexOfFirstOperand)) ==
PreviousLinkV &&
"PreviousLinkV must be the operand other than VecOp");
PreviousLink &&
"PreviousLink must be the operand other than VecOp");
}

BasicBlock *BB = CurrentLinkI->getParent();
Expand All @@ -9051,13 +9050,13 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
}

VPReductionRecipe *RedRecipe = new VPReductionRecipe(
RdxDesc, CurrentLinkI, PreviousLinkV, VecOp, CondOp);
RdxDesc, CurrentLinkI, PreviousLink, VecOp, CondOp);
// Append the recipe to the end of the VPBasicBlock because we need to
// ensure that it comes after all of it's inputs, including CondOp.
// Note that this transformation may leave over dead recipes (including
// CurrentLink), which will be cleaned by a later VPlan transform.
LinkVPBB->appendRecipe(RedRecipe);
CurrentLink->getVPSingleValue()->replaceAllUsesWith(RedRecipe);
CurrentLink->replaceAllUsesWith(RedRecipe);
PreviousLink = RedRecipe;
}
}
Expand Down
Loading