Skip to content

Commit ee80664

Browse files
committed
[VPlan] Consistently use hasScalarVFOnly (NFC).
Consistently use hasScalarVFOnly instead of using hasVF(ElementCount::getFixed(1)). Also add an assert to ensure all cases are covered by hasScalarVFOnly.
1 parent 0cdb467 commit ee80664

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4559,11 +4559,10 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
45594559
InstructionCost ExpectedCost = CM.expectedCost(ElementCount::getFixed(1));
45604560
LLVM_DEBUG(dbgs() << "LV: Scalar loop costs: " << ExpectedCost << ".\n");
45614561
assert(ExpectedCost.isValid() && "Unexpected invalid cost for scalar loop");
4562-
assert(any_of(VPlans,
4563-
[](std::unique_ptr<VPlan> &P) {
4564-
return P->hasVF(ElementCount::getFixed(1));
4565-
}) &&
4566-
"Expected Scalar VF to be a candidate");
4562+
assert(
4563+
any_of(VPlans,
4564+
[](std::unique_ptr<VPlan> &P) { return P->hasScalarVFOnly(); }) &&
4565+
"Expected Scalar VF to be a candidate");
45674566

45684567
const VectorizationFactor ScalarCost(ElementCount::getFixed(1), ExpectedCost,
45694568
ExpectedCost);
@@ -8929,7 +8928,7 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
89298928
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
89308929
VFRange SubRange = {VF, MaxVFTimes2};
89318930
if (auto Plan = tryToBuildVPlanWithVPRecipes(SubRange)) {
8932-
bool HasScalarVF = Plan->hasVF(ElementCount::getFixed(1));
8931+
bool HasScalarVF = Plan->hasScalarVFOnly();
89338932
// Now optimize the initial VPlan.
89348933
if (!HasScalarVF)
89358934
VPlanTransforms::runPass(VPlanTransforms::truncateToMinimalBitwidths,

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3680,7 +3680,12 @@ class VPlan {
36803680
return {VFs.begin(), VFs.end()};
36813681
}
36823682

3683-
bool hasScalarVFOnly() const { return VFs.size() == 1 && VFs[0].isScalar(); }
3683+
bool hasScalarVFOnly() const {
3684+
bool HasScalarVFOnly = VFs.size() == 1 && VFs[0].isScalar();
3685+
assert(HasScalarVFOnly == hasVF(ElementCount::getFixed(1)) &&
3686+
"Plan with scalar VF should only have a single VF");
3687+
return HasScalarVFOnly;
3688+
}
36843689

36853690
bool hasUF(unsigned UF) const { return UFs.empty() || UFs.contains(UF); }
36863691

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ static SmallVector<VPUser *> collectUsersRecursively(VPValue *V) {
591591
static void legalizeAndOptimizeInductions(VPlan &Plan) {
592592
using namespace llvm::VPlanPatternMatch;
593593
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
594-
bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));
594+
bool HasOnlyVectorVFs = !Plan.hasScalarVFOnly();
595595
VPBuilder Builder(HeaderVPBB, HeaderVPBB->getFirstNonPhi());
596596
for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
597597
auto *PhiR = dyn_cast<VPWidenInductionRecipe>(&Phi);

0 commit comments

Comments
 (0)