Skip to content

Commit 8be25aa

Browse files
committed
[VPlan] Construct initial once and pass clones to tryToBuildVPlan (NFC).
Update to only build an initial, plain-CFG VPlan once, and then transform & optimize clones. This requires changes to ::clone() for VPInstruction and VPWidenPHIRecipe to allow for proper cloning of the recipes in the initial VPlan.
1 parent dcef154 commit 8be25aa

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ class LoopVectorizationPlanner {
524524
/// returned VPlan is valid for. If no VPlan can be built for the input range,
525525
/// set the largest included VF to the maximum VF for which no plan could be
526526
/// built.
527-
VPlanPtr tryToBuildVPlanWithVPRecipes(VFRange &Range, LoopVersioning *LVer);
527+
VPlanPtr tryToBuildVPlanWithVPRecipes(VPlanPtr InitialPlan, VFRange &Range,
528+
LoopVersioning *LVer);
528529

529530
/// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,
530531
/// according to the information gathered by Legal when it checked if it is

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8715,11 +8715,13 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
87158715
// overlap across all iterations.
87168716
LVer.prepareNoAliasMetadata();
87178717
}
8718+
auto VPlan0 = VPlanTransforms::buildPlainCFG(OrigLoop, *LI);
87188719

87198720
auto MaxVFTimes2 = MaxVF * 2;
87208721
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
87218722
VFRange SubRange = {VF, MaxVFTimes2};
8722-
if (auto Plan = tryToBuildVPlanWithVPRecipes(SubRange, &LVer)) {
8723+
if (auto Plan = tryToBuildVPlanWithVPRecipes(
8724+
std::unique_ptr<VPlan>(VPlan0->duplicate()), SubRange, &LVer)) {
87238725
bool HasScalarVF = Plan->hasScalarVFOnly();
87248726
// Now optimize the initial VPlan.
87258727
if (!HasScalarVF)
@@ -8980,9 +8982,8 @@ static void addExitUsersForFirstOrderRecurrences(
89808982
}
89818983
}
89828984

8983-
VPlanPtr
8984-
LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
8985-
LoopVersioning *LVer) {
8985+
VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
8986+
VPlanPtr Plan, VFRange &Range, LoopVersioning *LVer) {
89868987

89878988
using namespace llvm::VPlanPatternMatch;
89888989
SmallPtrSet<const InterleaveGroup<Instruction> *, 1> InterleaveGroups;
@@ -9004,7 +9005,6 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
90049005
return !CM.requiresScalarEpilogue(VF.isVector());
90059006
},
90069007
Range);
9007-
auto Plan = VPlanTransforms::buildPlainCFG(OrigLoop, *LI);
90089008
VPlanTransforms::prepareForVectorization(
90099009
*Plan, Legal->getWidestInductionType(), PSE, RequiresScalarEpilogueCheck,
90109010
CM.foldTailByMasking(), OrigLoop,

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,8 @@ class VPInstruction : public VPRecipeWithIRFlags,
10041004
VPInstruction *clone() override {
10051005
SmallVector<VPValue *, 2> Operands(operands());
10061006
auto *New = new VPInstruction(Opcode, Operands, getDebugLoc(), Name);
1007+
if (getUnderlyingValue())
1008+
New->setUnderlyingValue(getUnderlyingInstr());
10071009
New->transferFlags(*this);
10081010
return New;
10091011
}
@@ -2129,7 +2131,11 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe, public VPPhiAccessors {
21292131
}
21302132

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

21352141
~VPWidenPHIRecipe() override = default;

0 commit comments

Comments
 (0)