Skip to content

Commit fcec875

Browse files
authored
[LoopVectorize][NFC] Simplify ScaledReductionExitInstrs map (#123368)
For the following variable DenseMap<const Instruction *, std::pair<PartialReductionChain, unsigned>> ScaledReductionExitInstrs; we never actually need the PartialReductionChain when using the map. I've cleaned this up so that this now becomes DenseMap<const Instruction *, unsigned> ScaledReductionMap;
1 parent 723a3e7 commit fcec875

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8711,7 +8711,7 @@ void VPRecipeBuilder::collectScaledReductions(VFRange &Range) {
87118711
PartialReductionChain Chain = Pair.first;
87128712
if (ExtendIsOnlyUsedByPartialReductions(Chain.ExtendA) &&
87138713
ExtendIsOnlyUsedByPartialReductions(Chain.ExtendB))
8714-
ScaledReductionExitInstrs.insert(std::make_pair(Chain.Reduction, Pair));
8714+
ScaledReductionMap.insert(std::make_pair(Chain.Reduction, Pair.second));
87158715
}
87168716
}
87178717

@@ -8803,9 +8803,8 @@ VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
88038803
Phi->getIncomingValueForBlock(OrigLoop->getLoopPreheader()));
88048804

88058805
// If the PHI is used by a partial reduction, set the scale factor.
8806-
std::optional<std::pair<PartialReductionChain, unsigned>> Pair =
8807-
getScaledReductionForInstr(RdxDesc.getLoopExitInstr());
8808-
unsigned ScaleFactor = Pair ? Pair->second : 1;
8806+
unsigned ScaleFactor =
8807+
getScalingForReduction(RdxDesc.getLoopExitInstr()).value_or(1);
88098808
PhiRecipe = new VPReductionPHIRecipe(
88108809
Phi, RdxDesc, *StartV, CM.isInLoopReduction(Phi),
88118810
CM.useOrderedReductions(RdxDesc), ScaleFactor);
@@ -8840,7 +8839,7 @@ VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
88408839
if (isa<LoadInst>(Instr) || isa<StoreInst>(Instr))
88418840
return tryToWidenMemory(Instr, Operands, Range);
88428841

8843-
if (getScaledReductionForInstr(Instr))
8842+
if (getScalingForReduction(Instr))
88448843
return tryToCreatePartialReduction(Instr, Operands);
88458844

88468845
if (!shouldWiden(Instr, Range))

llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ class VPRecipeBuilder {
8686
/// created.
8787
SmallVector<VPHeaderPHIRecipe *, 4> PhisToFix;
8888

89-
/// The set of reduction exit instructions that will be scaled to
90-
/// a smaller VF via partial reductions, paired with the scaling factor.
91-
DenseMap<const Instruction *, std::pair<PartialReductionChain, unsigned>>
92-
ScaledReductionExitInstrs;
89+
/// A mapping of partial reduction exit instructions to their scaling factor.
90+
DenseMap<const Instruction *, unsigned> ScaledReductionMap;
9391

9492
/// Check if \p I can be widened at the start of \p Range and possibly
9593
/// decrease the range such that the returned value holds for the entire \p
@@ -157,12 +155,10 @@ class VPRecipeBuilder {
157155
: Plan(Plan), OrigLoop(OrigLoop), TLI(TLI), TTI(TTI), Legal(Legal),
158156
CM(CM), PSE(PSE), Builder(Builder) {}
159157

160-
std::optional<std::pair<PartialReductionChain, unsigned>>
161-
getScaledReductionForInstr(const Instruction *ExitInst) {
162-
auto It = ScaledReductionExitInstrs.find(ExitInst);
163-
return It == ScaledReductionExitInstrs.end()
164-
? std::nullopt
165-
: std::make_optional(It->second);
158+
std::optional<unsigned> getScalingForReduction(const Instruction *ExitInst) {
159+
auto It = ScaledReductionMap.find(ExitInst);
160+
return It == ScaledReductionMap.end() ? std::nullopt
161+
: std::make_optional(It->second);
166162
}
167163

168164
/// Find all possible partial reductions in the loop and track all of those

0 commit comments

Comments
 (0)