Skip to content

Commit 519cf3c

Browse files
committed
[VPlan] Remove unneeded getDefiningRecipe with isa/cast/dyn_cast. (NFC)
Classof for most recipes directly supports VPValue, so there is no need to call getDefiningRecipe when using isa/cast/dyn_cast.
1 parent 47a3ea4 commit 519cf3c

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8228,9 +8228,7 @@ VPRecipeBuilder::tryToCreatePartialReduction(VPInstruction *Reduction,
82288228

82298229
VPValue *BinOp = Reduction->getOperand(0);
82308230
VPValue *Accumulator = Reduction->getOperand(1);
8231-
VPRecipeBase *BinOpRecipe = BinOp->getDefiningRecipe();
8232-
if (isa<VPReductionPHIRecipe>(BinOpRecipe) ||
8233-
isa<VPPartialReductionRecipe>(BinOpRecipe))
8231+
if (isa<VPReductionPHIRecipe>(BinOp) || isa<VPPartialReductionRecipe>(BinOp))
82348232
std::swap(BinOp, Accumulator);
82358233

82368234
assert(ScaleFactor ==
@@ -8798,7 +8796,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
87988796
// with fewer lanes than the VF. So the operands of the select would have
87998797
// different numbers of lanes. Partial reductions mask the input instead.
88008798
if (!PhiR->isInLoop() && CM.foldTailByMasking() &&
8801-
!isa<VPPartialReductionRecipe>(OrigExitingVPV->getDefiningRecipe())) {
8799+
!isa<VPPartialReductionRecipe>(OrigExitingVPV)) {
88028800
VPValue *Cond = RecipeBuilder.getBlockInMask(PhiR->getParent());
88038801
std::optional<FastMathFlags> FMFs =
88048802
PhiTy->isFloatingPointTy()

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const {
14281428
void VPSlotTracker::assignName(const VPValue *V) {
14291429
assert(!VPValue2Name.contains(V) && "VPValue already has a name!");
14301430
auto *UV = V->getUnderlyingValue();
1431-
auto *VPI = dyn_cast_or_null<VPInstruction>(V->getDefiningRecipe());
1431+
auto *VPI = dyn_cast_or_null<VPInstruction>(V);
14321432
if (!UV && !(VPI && !VPI->getName().empty())) {
14331433
VPValue2Name[V] = (Twine("vp<%") + Twine(NextSlot) + ">").str();
14341434
NextSlot++;

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,8 @@ void VPlanTransforms::addMinimumVectorEpilogueIterationCheck(
798798

799799
bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
800800
auto GetMinMaxCompareValue = [](VPReductionPHIRecipe *RedPhiR) -> VPValue * {
801-
auto *MinMaxR = dyn_cast<VPRecipeWithIRFlags>(
802-
RedPhiR->getBackedgeValue()->getDefiningRecipe());
801+
auto *MinMaxR =
802+
dyn_cast_or_null<VPRecipeWithIRFlags>(RedPhiR->getBackedgeValue());
803803
if (!MinMaxR)
804804
return nullptr;
805805

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ VPPartialReductionRecipe::computeCost(ElementCount VF,
356356
// recipe.
357357
auto HandleWiden = [&](VPWidenRecipe *Widen) {
358358
if (match(Widen, m_Sub(m_ZeroInt(), m_VPValue(Op)))) {
359-
Widen = dyn_cast<VPWidenRecipe>(Op->getDefiningRecipe());
359+
Widen = dyn_cast<VPWidenRecipe>(Op);
360360
}
361361
Opcode = Widen->getOpcode();
362362
VPRecipeBase *ExtAR = Widen->getOperand(0)->getDefiningRecipe();
@@ -381,11 +381,10 @@ VPPartialReductionRecipe::computeCost(ElementCount VF,
381381
InputTypeA = Ctx.Types.inferScalarType(OpR->getOperand(0));
382382
ExtAType = GetExtendKind(OpR);
383383
} else if (isa<VPReductionPHIRecipe>(OpR)) {
384-
auto RedPhiOp1R = getOperand(1)->getDefiningRecipe();
385-
if (isa<VPWidenCastRecipe>(RedPhiOp1R)) {
384+
if (auto RedPhiOp1R = dyn_cast_or_null<VPWidenCastRecipe>(getOperand(1))) {
386385
InputTypeA = Ctx.Types.inferScalarType(RedPhiOp1R->getOperand(0));
387386
ExtAType = GetExtendKind(RedPhiOp1R);
388-
} else if (auto Widen = dyn_cast<VPWidenRecipe>(RedPhiOp1R))
387+
} else if (auto Widen = dyn_cast_or_null<VPWidenRecipe>(getOperand(1)))
389388
HandleWiden(Widen);
390389
} else if (auto Widen = dyn_cast<VPWidenRecipe>(OpR)) {
391390
HandleWiden(Widen);
@@ -3195,10 +3194,10 @@ bool VPReplicateRecipe::shouldPack() const {
31953194
static const SCEV *getAddressAccessSCEV(const VPValue *Ptr, ScalarEvolution &SE,
31963195
const Loop *L) {
31973196
auto *PtrR = Ptr->getDefiningRecipe();
3198-
if (!PtrR || !((isa<VPReplicateRecipe>(PtrR) &&
3199-
cast<VPReplicateRecipe>(PtrR)->getOpcode() ==
3197+
if (!PtrR || !((isa<VPReplicateRecipe>(Ptr) &&
3198+
cast<VPReplicateRecipe>(Ptr)->getOpcode() ==
32003199
Instruction::GetElementPtr) ||
3201-
isa<VPWidenGEPRecipe>(PtrR) ||
3200+
isa<VPWidenGEPRecipe>(Ptr) ||
32023201
match(Ptr, m_GetElementPtr(m_VPValue(), m_VPValue()))))
32033202
return nullptr;
32043203

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3719,11 +3719,9 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
37193719

37203720
// Try to match reduce.add(mul(...)).
37213721
if (match(VecOp, m_Mul(m_VPValue(A), m_VPValue(B)))) {
3722-
auto *RecipeA =
3723-
dyn_cast_if_present<VPWidenCastRecipe>(A->getDefiningRecipe());
3724-
auto *RecipeB =
3725-
dyn_cast_if_present<VPWidenCastRecipe>(B->getDefiningRecipe());
3726-
auto *Mul = cast<VPWidenRecipe>(VecOp->getDefiningRecipe());
3722+
auto *RecipeA = dyn_cast_if_present<VPWidenCastRecipe>(A);
3723+
auto *RecipeB = dyn_cast_if_present<VPWidenCastRecipe>(B);
3724+
auto *Mul = cast<VPWidenRecipe>(VecOp);
37273725

37283726
// Convert reduce.add(mul(ext, const)) to reduce.add(mul(ext, ext(const)))
37293727
ExtendAndReplaceConstantOp(RecipeA, RecipeB, B, Mul);
@@ -3748,10 +3746,10 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
37483746

37493747
// Match reduce.add(ext(mul(A, B))).
37503748
if (match(VecOp, m_ZExtOrSExt(m_Mul(m_VPValue(A), m_VPValue(B))))) {
3751-
auto *Ext = cast<VPWidenCastRecipe>(VecOp->getDefiningRecipe());
3752-
auto *Mul = cast<VPWidenRecipe>(Ext->getOperand(0)->getDefiningRecipe());
3753-
auto *Ext0 = dyn_cast_if_present<VPWidenCastRecipe>(A->getDefiningRecipe());
3754-
auto *Ext1 = dyn_cast_if_present<VPWidenCastRecipe>(B->getDefiningRecipe());
3749+
auto *Ext = cast<VPWidenCastRecipe>(VecOp);
3750+
auto *Mul = cast<VPWidenRecipe>(Ext->getOperand(0));
3751+
auto *Ext0 = dyn_cast_if_present<VPWidenCastRecipe>(A);
3752+
auto *Ext1 = dyn_cast_if_present<VPWidenCastRecipe>(B);
37553753

37563754
// reduce.add(ext(mul(ext, const)))
37573755
// -> reduce.add(ext(mul(ext, ext(const))))
@@ -4329,12 +4327,12 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
43294327

43304328
// Check if all values feeding InterleaveR are matching wide recipes, which
43314329
// operands that can be narrowed.
4332-
auto *WideMember0 = dyn_cast_or_null<VPWidenRecipe>(
4333-
InterleaveR->getStoredValues()[0]->getDefiningRecipe());
4330+
auto *WideMember0 =
4331+
dyn_cast_or_null<VPWidenRecipe>(InterleaveR->getStoredValues()[0]);
43344332
if (!WideMember0)
43354333
return;
43364334
for (const auto &[I, V] : enumerate(InterleaveR->getStoredValues())) {
4337-
auto *R = dyn_cast_or_null<VPWidenRecipe>(V->getDefiningRecipe());
4335+
auto *R = dyn_cast_or_null<VPWidenRecipe>(V);
43384336
if (!R || R->getOpcode() != WideMember0->getOpcode() ||
43394337
R->getNumOperands() > 2)
43404338
return;

0 commit comments

Comments
 (0)