[llvm] [VPlan] Strip Idx arg in replaceUsesWithIf (NFC) (PR #229061)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 5 05:10:04 PDT 2026
https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/229061
The argument is unused in all sites.
>From 357bbc814cadc15ea831e79b6644dcb03877f94a Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Mon, 5 Oct 2026 13:04:10 +0100
Subject: [PATCH] [VPlan] Strip Idx arg in replaceUsesWithIf (NFC)
The argument is unused in all sites.
---
.../Transforms/Vectorize/LoopVectorize.cpp | 5 ++--
llvm/lib/Transforms/Vectorize/VPlan.cpp | 7 +++--
.../Vectorize/VPlanConstruction.cpp | 10 +++----
.../Vectorize/VPlanEVLTailFolding.cpp | 11 ++++----
.../Transforms/Vectorize/VPlanLowering.cpp | 19 ++++++-------
.../lib/Transforms/Vectorize/VPlanRecipes.cpp | 8 +++---
.../Transforms/Vectorize/VPlanTransforms.cpp | 27 +++++++++----------
llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp | 2 +-
llvm/lib/Transforms/Vectorize/VPlanUtils.cpp | 3 +--
llvm/lib/Transforms/Vectorize/VPlanValue.h | 5 ++--
10 files changed, 42 insertions(+), 55 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 19eb40f712f4f..d28760ae36397 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7313,8 +7313,7 @@ static MainPlanResumeMarkers preparePlanForMainVectorLoop(VPlan &MainPlan,
VPInstruction *Freeze = Builder.createFreeze(OrigStart, {}, "fr");
VPI.setOperand(2, Freeze);
if (UpdateResumePhis)
- OrigStart->replaceUsesWithIf(
- Freeze, [](VPUser &U, unsigned) { return isa<VPPhi>(&U); });
+ OrigStart->replaceUsesWithIf(Freeze, IsaPred<VPPhi>);
}
};
AddFreezeForFindLastIVReductions(MainPlan, true);
@@ -7418,7 +7417,7 @@ static void preparePlanForEpilogueVectorLoop(
// version, except for the Add itself and the canonical IV increment.
auto *Increment = vputils::findCanonicalIVIncrement(Plan);
assert(Increment && "Must have a canonical IV increment at this point");
- IV->replaceUsesWithIf(Add, [Add, Increment](VPUser &U, unsigned) {
+ IV->replaceUsesWithIf(Add, [Add, Increment](VPUser &U) {
return &U != Add && &U != Increment;
});
VPInstruction *OffsetIVInc =
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index d5bd5ddbe0464..a8ed19188a224 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1462,14 +1462,13 @@ bool VPValue::isDefinedOutsideLoopRegions() const {
return !isDefinedInsideLoopRegions(this);
}
void VPValue::replaceAllUsesWith(VPValue *New) {
- replaceUsesWithIf(New, [](VPUser &, unsigned) { return true; });
+ replaceUsesWithIf(New, [](VPUser &) { return true; });
if (auto *SV = dyn_cast<VPSymbolicValue>(this))
SV->markMaterialized();
}
void VPValue::replaceUsesWithIf(
- VPValue *New,
- llvm::function_ref<bool(VPUser &U, unsigned Idx)> ShouldReplace) {
+ VPValue *New, llvm::function_ref<bool(VPUser &U)> ShouldReplace) {
assertNotMaterialized();
// Note that this early exit is required for correctness; the implementation
// below relies on the number of users for this VPValue to decrease, which
@@ -1481,7 +1480,7 @@ void VPValue::replaceUsesWithIf(
VPUser *User = Users[J];
bool RemovedUser = false;
for (unsigned I = 0, E = User->getNumOperands(); I < E; ++I) {
- if (User->getOperand(I) != this || !ShouldReplace(*User, I))
+ if (User->getOperand(I) != this || !ShouldReplace(*User))
continue;
RemovedUser = true;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
index e647b6c1586b0..525ddb5fd27ed 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
@@ -934,9 +934,8 @@ static bool tryToSinkOrHoistRecurrenceUsers(VPBasicBlock *HeaderVPBB,
auto *RecurSplice =
LoopBuilder.createNaryOp(VPInstruction::FirstOrderRecurrenceSplice,
{FOR, FOR->getBackedgeValue()});
- FOR->replaceUsesWithIf(RecurSplice, [RecurSplice](VPUser &U, unsigned) {
- return &U != RecurSplice;
- });
+ FOR->replaceUsesWithIf(
+ RecurSplice, [RecurSplice](VPUser &U) { return &U != RecurSplice; });
}
return true;
@@ -2402,7 +2401,6 @@ void VPlanTransforms::attachAliasMaskToHeaderMask(VPlan &Plan) {
// Update all existing users of the header mask to "HeaderMask & AliasMask".
auto *ClampedHeaderMask = Builder.createAnd(HeaderMask, AliasMask);
- HeaderMask->replaceUsesWithIf(ClampedHeaderMask, [&](VPUser &U, unsigned) {
- return &U != ClampedHeaderMask;
- });
+ HeaderMask->replaceUsesWithIf(
+ ClampedHeaderMask, [&](VPUser &U) { return &U != ClampedHeaderMask; });
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp b/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
index b6ede1c1edc7f..567b07c1eda6b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
@@ -374,11 +374,11 @@ static void fixupVFUsersForEVL(VPlan &Plan, VPValue &EVL) {
.createScalarZExtOrTrunc(&EVL, Plan.getVF().getScalarType(),
DebugLoc::getUnknown());
- Plan.getVF().replaceUsesWithIf(EVLAsIdx, [](VPUser &U, unsigned Idx) {
+ Plan.getVF().replaceUsesWithIf(EVLAsIdx, [](VPUser &U) {
return isa<VPWidenIntOrFpInductionRecipe, VPScalarIVStepsRecipe>(U);
});
- Plan.getVFxUF().replaceUsesWithIf(EVLAsIdx, [](VPUser &U, unsigned Idx) {
+ Plan.getVFxUF().replaceUsesWithIf(EVLAsIdx, [](VPUser &U) {
// Only replace uses in VPWidenPointerInductionRecipe; The increment of the
// canonical induction must not be updated.
return isa<VPWidenPointerInductionRecipe>(U);
@@ -553,10 +553,9 @@ void VPlanTransforms::addExplicitVectorLength(
// Replace all uses of the canonical IV with VPCurrentIterationPHIRecipe
// except for the canonical IV increment.
- CanonicalIV->replaceUsesWithIf(CurrentIteration,
- [CanonicalIVIncrement](VPUser &U, unsigned) {
- return &U != CanonicalIVIncrement;
- });
+ CanonicalIV->replaceUsesWithIf(
+ CurrentIteration,
+ [CanonicalIVIncrement](VPUser &U) { return &U != CanonicalIVIncrement; });
// TODO: support unroll factor > 1.
Plan.setUF(1);
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp b/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp
index 32af9efdc889e..42e3c30c30d88 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp
@@ -748,10 +748,9 @@ void VPlanTransforms::materializeBroadcasts(VPlan &Plan) {
VPBuilder Builder(cast<VPBasicBlock>(HoistBlock), HoistPoint);
auto *Broadcast = Builder.createNaryOp(VPInstruction::Broadcast, {VPV});
- VPV->replaceUsesWithIf(Broadcast,
- [VPV, Broadcast](VPUser &U, unsigned Idx) {
- return Broadcast != &U && !U.usesScalars(VPV);
- });
+ VPV->replaceUsesWithIf(Broadcast, [VPV, Broadcast](VPUser &U) {
+ return Broadcast != &U && !U.usesScalars(VPV);
+ });
}
}
@@ -837,8 +836,8 @@ void VPlanTransforms::materializePacksAndUnpacks(VPlan &Plan) {
BuildVector->insertAfter(DefR);
DefR->replaceUsesWithIf(
- BuildVector, [BuildVector, &UsesVectorOrInsideReplicateRegion](
- VPUser &U, unsigned) {
+ BuildVector,
+ [BuildVector, &UsesVectorOrInsideReplicateRegion](VPUser &U) {
return &U != BuildVector && UsesVectorOrInsideReplicateRegion(&U);
});
}
@@ -874,9 +873,8 @@ void VPlanTransforms::materializePacksAndUnpacks(VPlan &Plan) {
Unpack->insertBefore(*VPBB, VPBB->getFirstNonPhi());
else
Unpack->insertAfter(&R);
- Def->replaceUsesWithIf(Unpack, [&Def](VPUser &U, unsigned) {
- return U.usesFirstLaneOnly(Def);
- });
+ Def->replaceUsesWithIf(
+ Unpack, [&Def](VPUser &U) { return U.usesFirstLaneOnly(Def); });
}
}
}
@@ -981,8 +979,7 @@ void VPlanTransforms::materializeFactors(VPlan &Plan, VPBasicBlock *VectorPH,
VPValue *RuntimeVF = Builder.createElementCount(TCTy, VFEC);
if (!vputils::onlyScalarValuesUsed(&VF)) {
VPValue *BC = Builder.createNaryOp(VPInstruction::Broadcast, RuntimeVF);
- VF.replaceUsesWithIf(
- BC, [&VF](VPUser &U, unsigned) { return !U.usesScalars(&VF); });
+ VF.replaceUsesWithIf(BC, [&VF](VPUser &U) { return !U.usesScalars(&VF); });
}
VF.replaceAllUsesWith(RuntimeVF);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 11ced87c7ed5e..6d0eba2b5fa57 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -3677,10 +3677,10 @@ VPExpressionRecipe::VPExpressionRecipe(
// There are users outside of the expression. Clone the recipe and use the
// clone those external users.
VPSingleDefRecipe *CopyForExtUsers = R->clone();
- R->replaceUsesWithIf(CopyForExtUsers, [&ExpressionRecipesAsSetOfUsers](
- VPUser &U, unsigned) {
- return !ExpressionRecipesAsSetOfUsers.contains(&U);
- });
+ R->replaceUsesWithIf(CopyForExtUsers,
+ [&ExpressionRecipesAsSetOfUsers](VPUser &U) {
+ return !ExpressionRecipesAsSetOfUsers.contains(&U);
+ });
CopyForExtUsers->insertBefore(R);
}
if (R->getParent())
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 909ef9b2b7788..35d62b5d03ba6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -404,7 +404,7 @@ static bool sinkScalarOperands(VPlan &Plan) {
}
Clone->insertBefore(SinkCandidate);
- SinkCandidate->replaceUsesWithIf(Clone, [SinkTo](VPUser &U, unsigned) {
+ SinkCandidate->replaceUsesWithIf(Clone, [SinkTo](VPUser &U) {
return cast<VPRecipeBase>(&U)->getParent() != SinkTo;
});
}
@@ -518,7 +518,7 @@ static bool mergeReplicateRegionsIntoSuccessors(VPlan &Plan) {
VPValue *PredInst1 =
cast<VPPredInstPHIRecipe>(&Phi1ToMove)->getOperand(0);
VPValue *Phi1ToMoveV = Phi1ToMove.getVPSingleValue();
- Phi1ToMoveV->replaceUsesWithIf(PredInst1, [Then2](VPUser &U, unsigned) {
+ Phi1ToMoveV->replaceUsesWithIf(PredInst1, [Then2](VPUser &U) {
return cast<VPRecipeBase>(&U)->getParent() == Then2;
});
@@ -861,12 +861,11 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
WideIV->replaceAllUsesWith(Steps);
} else {
bool HasScalableVF = Plan.hasScalableVF();
- WideIV->replaceUsesWithIf(Steps,
- [WideIV, HasScalableVF](VPUser &U, unsigned) {
- if (HasScalableVF)
- return U.usesFirstLaneOnly(WideIV);
- return U.usesScalars(WideIV);
- });
+ WideIV->replaceUsesWithIf(Steps, [WideIV, HasScalableVF](VPUser &U) {
+ if (HasScalableVF)
+ return U.usesFirstLaneOnly(WideIV);
+ return U.usesScalars(WideIV);
+ });
}
}
}
@@ -1664,7 +1663,7 @@ static VPSingleDefRecipe *combineRecipe(VPlan &Plan, VPSingleDefRecipe *Def,
// Replace uses of a BuildVector by users that only use its first lane with
// its first operand directly.
if (match(Def, m_BuildVector())) {
- Def->replaceUsesWithIf(Def->getOperand(0), [Def](VPUser &U, unsigned) {
+ Def->replaceUsesWithIf(Def->getOperand(0), [Def](VPUser &U) {
return U.usesFirstLaneOnly(Def);
});
return Def;
@@ -1682,7 +1681,7 @@ static VPSingleDefRecipe *combineRecipe(VPlan &Plan, VPSingleDefRecipe *Def,
if (match(Def, m_Broadcast(m_VPValue(X)))) {
Def->replaceUsesWithIf(
- X, [Def](const VPUser &U, unsigned) { return U.usesScalars(Def); });
+ X, [Def](const VPUser &U) { return U.usesScalars(Def); });
return Def;
}
@@ -1727,7 +1726,7 @@ static VPSingleDefRecipe *combineRecipe(VPlan &Plan, VPSingleDefRecipe *Def,
VPValue *StartV;
if (match(Def, m_VPInstruction<VPInstruction::ReductionStartVector>(
m_VPValue(StartV), m_VPValue(), m_VPValue()))) {
- Def->replaceUsesWithIf(StartV, [](const VPUser &U, unsigned Idx) {
+ Def->replaceUsesWithIf(StartV, [](const VPUser &U) {
auto *PhiR = dyn_cast<VPReductionPHIRecipe>(&U);
return PhiR && PhiR->isInLoop();
});
@@ -2765,8 +2764,7 @@ void VPlanTransforms::replaceSymbolicStrides(
assert(!Plan.getVectorLoopRegion() &&
"expected to run before loop regions are created");
const auto &[Header, _] = VPBlockUtils::getPlainCFGHeaderAndLatch(Plan);
- auto CanUseVersionedStride = [&VPDT, Header = Header, &Plan](VPUser &U,
- unsigned Idx) {
+ auto CanUseVersionedStride = [&VPDT, Header = Header, &Plan](VPUser &U) {
auto *R = cast<VPRecipeBase>(&U);
// Skip phis if the loop if loop is not yet guarded.
if (isa<VPPhiAccessors>(R) &&
@@ -5286,8 +5284,7 @@ static void transformToPartialReduction(const VPPartialReductionChain &Chain,
SubOpc, {OldStartValue, RdxResult}, VPIRFlags::getDefaultFlags(SubOpc),
RdxPhi->getDebugLoc());
RdxResult->replaceUsesWithIf(
- NewResult,
- [&NewResult](VPUser &U, unsigned Idx) { return &U != NewResult; });
+ NewResult, [&NewResult](VPUser &U) { return &U != NewResult; });
}
/// Returns the cost of a link in a partial-reduction chain for a given VF.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
index d1e30ab0cff65..43e3d08291bdc 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
@@ -991,7 +991,7 @@ void VPlanTransforms::replicateByVF(VPlan &Plan, ElementCount VF) {
Def2LaneDefs[DefR] = LaneDefs;
/// Users that only demand the first lane can use the definition for lane
/// 0.
- DefR->replaceUsesWithIf(LaneDefs[0], [DefR](VPUser &U, unsigned) {
+ DefR->replaceUsesWithIf(LaneDefs[0], [DefR](VPUser &U) {
if (U.usesFirstLaneOnly(DefR))
return true;
auto *VPI = dyn_cast<VPInstruction>(&U);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index af36cb7274c94..3b82a2294c5d8 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -1434,8 +1434,7 @@ void vputils::detail::pullOutPermutationsImpl(
VPSingleDefRecipe *Res = BuildPerm(&Def);
Res->insertAfter(&Def);
- Def.replaceUsesWithIf(
- Res, [&Res](VPUser &U, unsigned _) { return &U != Res; });
+ Def.replaceUsesWithIf(Res, [&Res](VPUser &U) { return &U != Res; });
}
}
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index 7256c3b4e1f5d..305a1a0f9a0e2 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -186,9 +186,8 @@ class LLVM_ABI_FOR_TEST VPValue {
/// Go through the uses list for this VPValue and make each use point to \p
/// New if the callback ShouldReplace returns true for the given use specified
/// by a pair of (VPUser, the use index).
- void replaceUsesWithIf(
- VPValue *New,
- llvm::function_ref<bool(VPUser &U, unsigned Idx)> ShouldReplace);
+ void replaceUsesWithIf(VPValue *New,
+ llvm::function_ref<bool(VPUser &U)> ShouldReplace);
/// Returns the recipe defining this VPValue or nullptr if it is not defined
/// by a recipe, i.e. is a live-in.
More information about the llvm-commits
mailing list