Skip to content

Commit 1fae589

Browse files
committed
[LV] Return optz VPlan when trying to build (NFC)
1 parent 148a835 commit 1fae589

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8229,20 +8229,8 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
82298229
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
82308230
VFRange SubRange = {VF, MaxVFTimes2};
82318231
if (auto Plan = tryToBuildVPlanWithVPRecipes(
8232-
std::unique_ptr<VPlan>(VPlan0->duplicate()), SubRange, &LVer)) {
8233-
bool HasScalarVF = Plan->hasScalarVFOnly();
8234-
// Now optimize the initial VPlan.
8235-
if (!HasScalarVF)
8236-
VPlanTransforms::runPass(VPlanTransforms::truncateToMinimalBitwidths,
8237-
*Plan, CM.getMinimalBitwidths());
8238-
VPlanTransforms::runPass(VPlanTransforms::optimize, *Plan);
8239-
// TODO: try to put it close to addActiveLaneMask().
8240-
if (CM.foldTailWithEVL() && !HasScalarVF)
8241-
VPlanTransforms::runPass(VPlanTransforms::addExplicitVectorLength,
8242-
*Plan, CM.getMaxSafeElements());
8243-
assert(verifyVPlanIsValid(*Plan) && "VPlan is invalid");
8232+
std::unique_ptr<VPlan>(VPlan0->duplicate()), SubRange, &LVer))
82448233
VPlans.push_back(std::move(Plan));
8245-
}
82468234
VF = SubRange.End;
82478235
}
82488236
}
@@ -8709,6 +8697,12 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
87098697
WithoutRuntimeCheck);
87108698
}
87118699
VPlanTransforms::optimizeInductionExitUsers(*Plan, IVEndValues, *PSE.getSE());
8700+
VPlanTransforms::runPass(VPlanTransforms::truncateToMinimalBitwidths, *Plan,
8701+
CM.getMinimalBitwidths());
8702+
VPlanTransforms::runPass(VPlanTransforms::optimize, *Plan);
8703+
if (CM.foldTailWithEVL())
8704+
VPlanTransforms::runPass(VPlanTransforms::addExplicitVectorLength, *Plan,
8705+
CM.getMaxSafeElements());
87128706

87138707
assert(verifyVPlanIsValid(*Plan) && "VPlan is invalid");
87148708
return Plan;

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,9 @@ static void licm(VPlan &Plan) {
21042104

21052105
void VPlanTransforms::truncateToMinimalBitwidths(
21062106
VPlan &Plan, const MapVector<Instruction *, uint64_t> &MinBWs) {
2107+
if (Plan.hasScalarVFOnly())
2108+
return;
2109+
21072110
// Keep track of created truncates, so they can be re-used. Note that we
21082111
// cannot use RAUW after creating a new truncate, as this would could make
21092112
// other uses have different types for their operands, making them invalidly
@@ -2681,6 +2684,9 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
26812684
///
26822685
void VPlanTransforms::addExplicitVectorLength(
26832686
VPlan &Plan, const std::optional<unsigned> &MaxSafeElements) {
2687+
if (Plan.hasScalarVFOnly())
2688+
return;
2689+
26842690
VPBasicBlock *Header = Plan.getVectorLoopRegion()->getEntryBasicBlock();
26852691

26862692
auto *CanonicalIVPHI = Plan.getCanonicalIV();

0 commit comments

Comments
 (0)