[llvm] c5fff13 - [LV] Add LVL::getRecurrenceDescriptor (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 6 12:32:24 PDT 2025
Author: Florian Hahn
Date: 2025-07-06T20:31:38+01:00
New Revision: c5fff132d019557e9cb028859ee989ea97b50e5c
URL: https://github.com/llvm/llvm-project/commit/c5fff132d019557e9cb028859ee989ea97b50e5c
DIFF: https://github.com/llvm/llvm-project/commit/c5fff132d019557e9cb028859ee989ea97b50e5c.diff
LOG: [LV] Add LVL::getRecurrenceDescriptor (NFC).
Split off adding helper to retrieve RecurrenceDescriptor as suggested
from https://github.com/llvm/llvm-project/pull/142322.
Added:
Modified:
llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
index d654ac3ec9273..cba37363d0474 100644
--- a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
+++ b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
@@ -301,6 +301,14 @@ class LoopVectorizationLegality {
/// Returns the reduction variables found in the loop.
const ReductionList &getReductionVars() const { return Reductions; }
+ /// Returns the recurrence descriptor associated with a given phi node \p PN,
+ /// expecting one to exist.
+ const RecurrenceDescriptor &getRecurrenceDescriptor(PHINode *PN) const {
+ assert(isReductionVariable(PN) &&
+ "only reductions have recurrence descriptors");
+ return Reductions.find(PN)->second;
+ }
+
/// Returns the induction variables found in the loop.
const InductionList &getInductionVars() const { return Inductions; }
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 1209460237d93..586250ca63a4e 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4676,7 +4676,7 @@ void LoopVectorizationCostModel::collectElementTypesForWidening() {
if (!Legal->isReductionVariable(PN))
continue;
const RecurrenceDescriptor &RdxDesc =
- Legal->getReductionVars().find(PN)->second;
+ Legal->getRecurrenceDescriptor(PN);
if (PreferInLoopReductions || useOrderedReductions(RdxDesc) ||
TTI.preferInLoopReduction(RdxDesc.getRecurrenceKind(),
RdxDesc.getRecurrenceType()))
@@ -5476,7 +5476,7 @@ LoopVectorizationCostModel::getReductionPatternCost(Instruction *I,
ReductionPhi = InLoopReductionImmediateChains.at(ReductionPhi);
const RecurrenceDescriptor &RdxDesc =
- Legal->getReductionVars().find(cast<PHINode>(ReductionPhi))->second;
+ Legal->getRecurrenceDescriptor(cast<PHINode>(ReductionPhi));
InstructionCost BaseCost;
RecurKind RK = RdxDesc.getRecurrenceKind();
@@ -8300,8 +8300,7 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
"can only widen reductions and fixed-order recurrences here");
VPValue *StartV = Operands[0];
if (Legal->isReductionVariable(Phi)) {
- const RecurrenceDescriptor &RdxDesc =
- Legal->getReductionVars().find(Phi)->second;
+ const RecurrenceDescriptor &RdxDesc = Legal->getRecurrenceDescriptor(Phi);
assert(RdxDesc.getRecurrenceStartValue() ==
Phi->getIncomingValueForBlock(OrigLoop->getLoopPreheader()));
More information about the llvm-commits
mailing list