Skip to content

Commit c5fff13

Browse files
committed
[LV] Add LVL::getRecurrenceDescriptor (NFC).
Split off adding helper to retrieve RecurrenceDescriptor as suggested from #142322.
1 parent cf06047 commit c5fff13

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ class LoopVectorizationLegality {
301301
/// Returns the reduction variables found in the loop.
302302
const ReductionList &getReductionVars() const { return Reductions; }
303303

304+
/// Returns the recurrence descriptor associated with a given phi node \p PN,
305+
/// expecting one to exist.
306+
const RecurrenceDescriptor &getRecurrenceDescriptor(PHINode *PN) const {
307+
assert(isReductionVariable(PN) &&
308+
"only reductions have recurrence descriptors");
309+
return Reductions.find(PN)->second;
310+
}
311+
304312
/// Returns the induction variables found in the loop.
305313
const InductionList &getInductionVars() const { return Inductions; }
306314

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4676,7 +4676,7 @@ void LoopVectorizationCostModel::collectElementTypesForWidening() {
46764676
if (!Legal->isReductionVariable(PN))
46774677
continue;
46784678
const RecurrenceDescriptor &RdxDesc =
4679-
Legal->getReductionVars().find(PN)->second;
4679+
Legal->getRecurrenceDescriptor(PN);
46804680
if (PreferInLoopReductions || useOrderedReductions(RdxDesc) ||
46814681
TTI.preferInLoopReduction(RdxDesc.getRecurrenceKind(),
46824682
RdxDesc.getRecurrenceType()))
@@ -5476,7 +5476,7 @@ LoopVectorizationCostModel::getReductionPatternCost(Instruction *I,
54765476
ReductionPhi = InLoopReductionImmediateChains.at(ReductionPhi);
54775477

54785478
const RecurrenceDescriptor &RdxDesc =
5479-
Legal->getReductionVars().find(cast<PHINode>(ReductionPhi))->second;
5479+
Legal->getRecurrenceDescriptor(cast<PHINode>(ReductionPhi));
54805480

54815481
InstructionCost BaseCost;
54825482
RecurKind RK = RdxDesc.getRecurrenceKind();
@@ -8300,8 +8300,7 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
83008300
"can only widen reductions and fixed-order recurrences here");
83018301
VPValue *StartV = Operands[0];
83028302
if (Legal->isReductionVariable(Phi)) {
8303-
const RecurrenceDescriptor &RdxDesc =
8304-
Legal->getReductionVars().find(Phi)->second;
8303+
const RecurrenceDescriptor &RdxDesc = Legal->getRecurrenceDescriptor(Phi);
83058304
assert(RdxDesc.getRecurrenceStartValue() ==
83068305
Phi->getIncomingValueForBlock(OrigLoop->getLoopPreheader()));
83078306

0 commit comments

Comments
 (0)