[llvm] [VPlan] Introduce VPValue::has[No]Users (NFC) (PR #203518)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 08:08:05 PDT 2026
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/203518
>From 3730d86c757d5e7648153c3d4eb57ea86eac379e Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Fri, 12 Jun 2026 13:28:12 +0100
Subject: [PATCH] [VPlan] Introduce VPValue::has[No]Users (NFC)
---
llvm/lib/Transforms/Vectorize/VPlan.cpp | 18 +++++++--------
llvm/lib/Transforms/Vectorize/VPlan.h | 2 +-
.../Transforms/Vectorize/VPlanAnalysis.cpp | 4 ++--
.../Vectorize/VPlanConstruction.cpp | 2 +-
.../Transforms/Vectorize/VPlanTransforms.cpp | 23 +++++++++----------
llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp | 2 +-
llvm/lib/Transforms/Vectorize/VPlanValue.h | 6 +++--
7 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 8565bb85c4314..2a401f546e71f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -832,7 +832,7 @@ void VPRegionBlock::dissolveToCFGLoop() {
auto *Header = cast<VPBasicBlock>(getEntry());
auto *ExitingLatch = cast<VPBasicBlock>(getExiting());
auto *CanIV = getCanonicalIV();
- if (CanIV->getNumUsers() > 0) {
+ if (CanIV->hasUsers()) {
VPlan &Plan = *getPlan();
auto *Zero = Plan.getZero(CanIV->getType());
DebugLoc DL = CanIV->getDebugLoc();
@@ -1085,25 +1085,25 @@ bool VPlan::isOuterLoop() const {
void VPlan::printLiveIns(raw_ostream &O) const {
VPSlotTracker SlotTracker(this);
- if (VF.getNumUsers() > 0) {
+ if (VF.hasUsers()) {
O << "\nLive-in ";
VF.printAsOperand(O, SlotTracker);
O << " = VF";
}
- if (UF.getNumUsers() > 0) {
+ if (UF.hasUsers()) {
O << "\nLive-in ";
UF.printAsOperand(O, SlotTracker);
O << " = UF";
}
- if (VFxUF.getNumUsers() > 0) {
+ if (VFxUF.hasUsers()) {
O << "\nLive-in ";
VFxUF.printAsOperand(O, SlotTracker);
O << " = VF * UF";
}
- if (VectorTripCount.getNumUsers() > 0) {
+ if (VectorTripCount.hasUsers()) {
O << "\nLive-in ";
VectorTripCount.printAsOperand(O, SlotTracker);
O << " = vector-trip-count";
@@ -1116,7 +1116,7 @@ void VPlan::printLiveIns(raw_ostream &O) const {
}
O << "\n";
- if (TripCount && TripCount->getNumUsers() > 0) {
+ if (TripCount && TripCount->hasUsers()) {
if (isa<VPIRValue>(TripCount))
O << "Live-in ";
TripCount->printAsOperand(O, SlotTracker);
@@ -1563,11 +1563,11 @@ void VPSlotTracker::assignName(const VPValue *V) {
}
void VPSlotTracker::assignNames(const VPlan &Plan) {
- if (Plan.VF.getNumUsers() > 0)
+ if (Plan.VF.hasUsers())
assignName(&Plan.VF);
- if (Plan.UF.getNumUsers() > 0)
+ if (Plan.UF.hasUsers())
assignName(&Plan.UF);
- if (Plan.VFxUF.getNumUsers() > 0)
+ if (Plan.VFxUF.hasUsers())
assignName(&Plan.VFxUF);
assignName(&Plan.VectorTripCount);
if (Plan.BackedgeTakenCount)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 26c528a323969..7275b4ca7bc05 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -4936,7 +4936,7 @@ class VPlan {
/// Resets the trip count for the VPlan. The caller must make sure all uses of
/// the original trip count have been replaced.
void resetTripCount(VPValue *NewTripCount) {
- assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
+ assert(TripCount && NewTripCount && TripCount->hasNoUsers() &&
"TripCount must be set when resetting");
TripCount = NewTripCount;
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 54f6c602f77d2..d42b0622f835d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -124,7 +124,7 @@ SmallVector<VPRegisterUsage, 8> llvm::calculateRegisterUsageForPlan(
// the loop (not including non-recipe values such as arguments and
// constants).
SmallSetVector<VPValue *, 8> LoopInvariants;
- if (Plan.getVectorTripCount().getNumUsers() > 0)
+ if (Plan.getVectorTripCount().hasUsers())
LoopInvariants.insert(&Plan.getVectorTripCount());
// We scan the loop in a topological order in order and assign a number to
@@ -198,7 +198,7 @@ SmallVector<VPRegisterUsage, 8> llvm::calculateRegisterUsageForPlan(
VPValue *CanIV = LoopRegion->getCanonicalIV();
// Note: canonical IVs are retained even if they have no users.
- if (CanIV->getNumUsers() != 0)
+ if (CanIV->hasUsers())
OpenIntervals.insert(CanIV);
// We scan the instructions linearly and record each time that a new interval
diff --git a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
index bb967d3f3daf0..619fea8c10b4d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
@@ -1767,7 +1767,7 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
continue;
if (auto *DerivedIV = dyn_cast<VPDerivedIVRecipe>(VecV)) {
VPValue *DIVTC = DerivedIV->getOperand(1);
- if (DerivedIV->getNumUsers() == 1 && IsTC(DIVTC)) {
+ if (DerivedIV->hasOneUse() && IsTC(DIVTC)) {
auto *NewSel = MiddleBuilder.createSelect(
AnyNaNLane, LoopRegion->getCanonicalIV(), DIVTC);
DerivedIV->moveAfter(&*MiddleBuilder.getInsertPoint());
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index adcfe30ff9561..35786f019d697 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -492,7 +492,7 @@ static bool mergeReplicateRegionsIntoSuccessors(VPlan &Plan) {
});
// Remove phi recipes that are unused after merging the regions.
- if (Phi1ToMove.getVPSingleValue()->getNumUsers() == 0) {
+ if (Phi1ToMove.getVPSingleValue()->hasNoUsers()) {
Phi1ToMove.eraseFromParent();
continue;
}
@@ -548,7 +548,7 @@ static VPRegionBlock *createReplicateRegion(VPReplicateRecipe *PredRecipe,
VPBlockUtils::insertTwoBlocksAfter(Pred, Exiting, Entry);
VPBlockUtils::connectBlocks(Pred, Exiting);
- if (PredRecipe->getNumUsers() != 0) {
+ if (PredRecipe->hasUsers()) {
auto *PHIRecipe = new VPPredInstPHIRecipe(RecipeWithoutMask,
RecipeWithoutMask->getDebugLoc());
Exiting->appendRecipe(PHIRecipe);
@@ -802,8 +802,7 @@ static bool isDeadRecipe(VPRecipeBase &R) {
return false;
// Recipe is dead if no user keeps the recipe alive.
- return all_of(R.definedValues(),
- [](VPValue *V) { return V->getNumUsers() == 0; });
+ return all_of(R.definedValues(), [](VPValue *V) { return V->hasNoUsers(); });
}
void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
@@ -894,7 +893,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
auto *RepR = dyn_cast<VPReplicateRecipe>(U);
// Skip recipes that shouldn't be narrowed.
if (!Def || !isa<VPReplicateRecipe, VPWidenRecipe>(Def) ||
- Def->getNumUsers() == 0 || !Def->getUnderlyingValue() ||
+ Def->hasNoUsers() || !Def->getUnderlyingValue() ||
(RepR && (RepR->isSingleScalar() || RepR->isPredicated())))
continue;
@@ -2063,7 +2062,7 @@ static void simplifyBlends(VPlan &Plan) {
// TODO: Find the most expensive mask that can be deadcoded, or a mask
// that's used by multiple blends where it can be removed from them all.
VPValue *Mask = Blend->getMask(I);
- if (Mask->getNumUsers() == 1 && !match(Mask, m_False())) {
+ if (Mask->hasOneUse() && !match(Mask, m_False())) {
StartIndex = I;
break;
}
@@ -2099,7 +2098,7 @@ static void simplifyBlends(VPlan &Plan) {
NewBlend->setOperand(0, Inc1);
NewBlend->setOperand(1, Inc0);
NewBlend->setOperand(2, NewMask);
- if (OldMask->getNumUsers() == 0)
+ if (OldMask->hasNoUsers())
cast<VPInstruction>(OldMask)->eraseFromParent();
}
}
@@ -5322,7 +5321,7 @@ void VPlanTransforms::materializeConstantVectorTripCount(
assert(Plan.hasUF(BestUF) && "BestUF is not available in Plan");
VPValue *TC = Plan.getTripCount();
- if (TC->getNumUsers() == 0)
+ if (TC->hasNoUsers())
return;
// Skip cases for which the trip count may be non-trivial to materialize.
@@ -5351,7 +5350,7 @@ void VPlanTransforms::materializeConstantVectorTripCount(
void VPlanTransforms::materializeBackedgeTakenCount(VPlan &Plan,
VPBasicBlock *VectorPH) {
VPValue *BTC = Plan.getOrCreateBackedgeTakenCount();
- if (BTC->getNumUsers() == 0)
+ if (BTC->hasNoUsers())
return;
VPBuilder Builder(VectorPH, VectorPH->begin());
@@ -5460,7 +5459,7 @@ void VPlanTransforms::materializeVectorTripCount(
VPSymbolicValue &VectorTC = Plan.getVectorTripCount();
// There's nothing to do if there are no users of the vector trip count or its
// IR value has already been set.
- if (VectorTC.getNumUsers() == 0 || VectorTC.getUnderlyingValue())
+ if (VectorTC.hasNoUsers() || VectorTC.getUnderlyingValue())
return;
VPValue *TC = Plan.getTripCount();
@@ -5540,7 +5539,7 @@ void VPlanTransforms::materializeFactors(VPlan &Plan, VPBasicBlock *VectorPH,
VPValue &VFxUF = Plan.getVFxUF();
// If there are no users of the runtime VF, compute VFxUF by constant folding
// the multiplication of VF and UF.
- if (VF.getNumUsers() == 0) {
+ if (VF.hasNoUsers()) {
VPValue *RuntimeVFxUF =
Builder.createElementCount(TCTy, VFEC * Plan.getConcreteUF());
VFxUF.replaceAllUsesWith(RuntimeVFxUF);
@@ -5695,7 +5694,7 @@ void VPlanTransforms::expandSCEVsToVPInstructions(VPlan &Plan,
// late expansion.
for (VPRecipeBase &R : make_early_inc_range(*Entry)) {
auto *ExpSCEV = dyn_cast<VPExpandSCEVRecipe>(&R);
- if (!ExpSCEV || ExpSCEV->getNumUsers() == 0)
+ if (!ExpSCEV || ExpSCEV->hasNoUsers())
continue;
Builder.setInsertPoint(ExpSCEV);
VPValue *Expanded = Expander.tryToExpand(ExpSCEV->getSCEV());
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
index 3c4dc12950823..5792b5a016f2f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
@@ -946,7 +946,7 @@ void VPlanTransforms::replicateByVF(VPlan &Plan, ElementCount VF) {
auto *DefR = cast<VPSingleDefRecipe>(&R);
VPBuilder Builder(DefR);
- if (DefR->getNumUsers() == 0) {
+ if (DefR->hasNoUsers()) {
// Create single-scalar version of DefR for all lanes.
for (unsigned I = 0; I != VF.getKnownMinValue(); ++I)
cloneForLane(Plan, Builder, IdxTy, DefR, VPLane(I), Def2LaneDefs);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index 8356bcb08634f..0722ef4d83a28 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -161,7 +161,7 @@ class LLVM_ABI_FOR_TEST VPValue {
/// Returns true if the value has more than one unique user.
bool hasMoreThanOneUniqueUser() const {
- if (getNumUsers() == 0)
+ if (hasNoUsers())
return false;
// Check if all users match the first user.
@@ -171,6 +171,8 @@ class LLVM_ABI_FOR_TEST VPValue {
return Current != user_end();
}
+ bool hasNoUsers() const { return Users.empty(); }
+ bool hasUsers() const { return !hasNoUsers(); }
bool hasOneUse() const { return getNumUsers() == 1; }
/// Return the single user of this value, or nullptr if there is not exactly
@@ -523,7 +525,7 @@ class VPDef {
for (VPRecipeValue *D : to_vector(DefinedValues)) {
assert(D->isDefinedBy(this) &&
"all defined VPValues should point to the containing VPDef");
- assert(D->getNumUsers() == 0 &&
+ assert(D->hasNoUsers() &&
"all defined VPValues should have no more users");
delete D;
}
More information about the llvm-commits
mailing list