Skip to content

[VPlan] Construct initial once and pass clones to tryToBuildVPlan (NFC). #141363

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 3 commits into from
May 26, 2025
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
6 changes: 4 additions & 2 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,10 @@ class LoopVectorizationPlanner {
/// \p Range's largest included VF is restricted to the maximum VF the
/// returned VPlan is valid for. If no VPlan can be built for the input range,
/// set the largest included VF to the maximum VF for which no plan could be
/// built.
VPlanPtr tryToBuildVPlanWithVPRecipes(VFRange &Range, LoopVersioning *LVer);
/// built. Each VPlan is built starting from a copy of \p InitialPlan, which
/// is a plain CFG VPlan wrapping the original scalar loop.
VPlanPtr tryToBuildVPlanWithVPRecipes(VPlanPtr InitialPlan, VFRange &Range,
LoopVersioning *LVer);

/// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,
/// according to the information gathered by Legal when it checked if it is
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8717,9 +8717,11 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
}

auto MaxVFTimes2 = MaxVF * 2;
auto VPlan0 = VPlanTransforms::buildPlainCFG(OrigLoop, *LI);
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
VFRange SubRange = {VF, MaxVFTimes2};
if (auto Plan = tryToBuildVPlanWithVPRecipes(SubRange, &LVer)) {
if (auto Plan = tryToBuildVPlanWithVPRecipes(
std::unique_ptr<VPlan>(VPlan0->duplicate()), SubRange, &LVer)) {
bool HasScalarVF = Plan->hasScalarVFOnly();
// Now optimize the initial VPlan.
if (!HasScalarVF)
Expand Down Expand Up @@ -8980,9 +8982,8 @@ static void addExitUsersForFirstOrderRecurrences(
}
}

VPlanPtr
LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
LoopVersioning *LVer) {
VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
VPlanPtr Plan, VFRange &Range, LoopVersioning *LVer) {

using namespace llvm::VPlanPatternMatch;
SmallPtrSet<const InterleaveGroup<Instruction> *, 1> InterleaveGroups;
Expand All @@ -9004,7 +9005,6 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
return !CM.requiresScalarEpilogue(VF.isVector());
},
Range);
auto Plan = VPlanTransforms::buildPlainCFG(OrigLoop, *LI);
VPlanTransforms::prepareForVectorization(
*Plan, Legal->getWidestInductionType(), PSE, RequiresScalarEpilogueCheck,
CM.foldTailByMasking(), OrigLoop,
Expand Down
11 changes: 9 additions & 2 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,10 @@ class VPInstruction : public VPRecipeWithIRFlags,

VPInstruction *clone() override {
SmallVector<VPValue *, 2> Operands(operands());
return new VPInstruction(Opcode, Operands, *this, getDebugLoc(), Name);
auto *New = new VPInstruction(Opcode, Operands, *this, getDebugLoc(), Name);
if (getUnderlyingValue())
New->setUnderlyingValue(getUnderlyingInstr());
return New;
}

unsigned getOpcode() const { return Opcode; }
Expand Down Expand Up @@ -2090,7 +2093,11 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe, public VPPhiAccessors {
}

VPWidenPHIRecipe *clone() override {
llvm_unreachable("cloning not implemented yet");
auto *C = new VPWidenPHIRecipe(cast<PHINode>(getUnderlyingValue()),
getOperand(0), getDebugLoc(), Name);
for (VPValue *Op : make_range(std::next(op_begin()), op_end()))
C->addOperand(Op);
return C;
}

~VPWidenPHIRecipe() override = default;
Expand Down