Skip to content

Commit 73f8609

Browse files
committed
Fold isCompatibleToEVLTransform into addExplicitVectorLength
1 parent fd0e6da commit 73f8609

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8539,20 +8539,6 @@ VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
85398539
return tryToWiden(Instr, Operands, VPBB);
85408540
}
85418541

8542-
// EVL transform doesn't support backends where EVL diffs from RuntimeVF
8543-
// in the second-to-last iteration.
8544-
// Return false if the vector region has recipes relying on
8545-
// RuntimeVF.
8546-
static bool isCompatibleToEVLTransform(VPlan &Plan) {
8547-
if (any_of(Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis(),
8548-
[](VPRecipeBase &Phi) {
8549-
return (isa<VPWidenIntOrFpInductionRecipe>(&Phi) ||
8550-
isa<VPWidenPointerInductionRecipe>(&Phi));
8551-
}))
8552-
return false;
8553-
return true;
8554-
}
8555-
85568542
void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
85578543
ElementCount MaxVF) {
85588544
assert(OrigLoop->isInnermost() && "Inner loop expected.");
@@ -8567,12 +8553,10 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
85678553
*Plan, CM.getMinimalBitwidths(), PSE.getSE()->getContext());
85688554
VPlanTransforms::optimize(*Plan, *PSE.getSE());
85698555
// TODO: try to put it close to addActiveLaneMask().
8570-
if (CM.foldTailWithEVL()) {
8571-
// Discard the plan if it is not EVL-compatible
8572-
if (!isCompatibleToEVLTransform(*Plan))
8573-
break;
8574-
VPlanTransforms::addExplicitVectorLength(*Plan);
8575-
}
8556+
// Discard the plan if it is not EVL-compatible
8557+
if (CM.foldTailWithEVL() &&
8558+
!VPlanTransforms::addExplicitVectorLength(*Plan))
8559+
break;
85768560
assert(verifyVPlanIsValid(*Plan) && "VPlan is invalid");
85778561
VPlans.push_back(std::move(Plan));
85788562
}

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,6 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags {
15761576

15771577
void execute(VPTransformState &State) override;
15781578

1579-
bool isReverse() { return IsReverse; }
15801579
bool onlyFirstLaneUsed(const VPValue *Op) const override {
15811580
assert(is_contained(operands(), Op) &&
15821581
"Op must be an operand of the recipe");

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,16 @@ void VPlanTransforms::addActiveLaneMask(
13061306
/// %NextEVLIV = add IVSize (cast i32 %VPEVVL to IVSize), %EVLPhi
13071307
/// ...
13081308
///
1309-
void VPlanTransforms::addExplicitVectorLength(VPlan &Plan) {
1309+
bool VPlanTransforms::addExplicitVectorLength(VPlan &Plan) {
1310+
// EVL transform doesn't support backends where EVL diffs from RuntimeVF
1311+
// in the second-to-last iteration.
1312+
// Return false if any recipes rely on RuntimeVF.
1313+
if (any_of(Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis(),
1314+
[](VPRecipeBase &Phi) {
1315+
return (isa<VPWidenIntOrFpInductionRecipe>(&Phi) ||
1316+
isa<VPWidenPointerInductionRecipe>(&Phi));
1317+
}))
1318+
return false;
13101319
VPBasicBlock *Header = Plan.getVectorLoopRegion()->getEntryBasicBlock();
13111320
auto *CanonicalIVPHI = Plan.getCanonicalIV();
13121321
VPValue *StartV = CanonicalIVPHI->getStartValue();
@@ -1367,6 +1376,7 @@ void VPlanTransforms::addExplicitVectorLength(VPlan &Plan) {
13671376
CanonicalIVIncrement->setOperand(0, CanonicalIVPHI);
13681377
// TODO: support unroll factor > 1.
13691378
Plan.setUF(1);
1379+
return true;
13701380
}
13711381

13721382
void VPlanTransforms::dropPoisonGeneratingRecipes(

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ struct VPlanTransforms {
104104
/// VPCanonicalIVPHIRecipe with a VPEVLBasedIVPHIRecipe.
105105
/// VPCanonicalIVPHIRecipe is only used to control the loop after
106106
/// this transformation.
107-
static void addExplicitVectorLength(VPlan &Plan);
107+
/// \returns true if the transformation succeeds, or false if it doesn't.
108+
static bool addExplicitVectorLength(VPlan &Plan);
108109
};
109110

110111
} // namespace llvm

0 commit comments

Comments
 (0)