[llvm] fcec875 - [LoopVectorize][NFC] Simplify ScaledReductionExitInstrs map (#123368)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 20 06:41:32 PST 2025
Author: David Sherwood
Date: 2025-01-20T14:41:27Z
New Revision: fcec8756e25333b6f49472f00e043f2389736c0b
URL: https://github.com/llvm/llvm-project/commit/fcec8756e25333b6f49472f00e043f2389736c0b
DIFF: https://github.com/llvm/llvm-project/commit/fcec8756e25333b6f49472f00e043f2389736c0b.diff
LOG: [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;
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f6f80db58cf1b0..29f3940ed6fa7a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8711,7 +8711,7 @@ void VPRecipeBuilder::collectScaledReductions(VFRange &Range) {
PartialReductionChain Chain = Pair.first;
if (ExtendIsOnlyUsedByPartialReductions(Chain.ExtendA) &&
ExtendIsOnlyUsedByPartialReductions(Chain.ExtendB))
- ScaledReductionExitInstrs.insert(std::make_pair(Chain.Reduction, Pair));
+ ScaledReductionMap.insert(std::make_pair(Chain.Reduction, Pair.second));
}
}
@@ -8803,9 +8803,8 @@ VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
Phi->getIncomingValueForBlock(OrigLoop->getLoopPreheader()));
// If the PHI is used by a partial reduction, set the scale factor.
- std::optional<std::pair<PartialReductionChain, unsigned>> Pair =
- getScaledReductionForInstr(RdxDesc.getLoopExitInstr());
- unsigned ScaleFactor = Pair ? Pair->second : 1;
+ unsigned ScaleFactor =
+ getScalingForReduction(RdxDesc.getLoopExitInstr()).value_or(1);
PhiRecipe = new VPReductionPHIRecipe(
Phi, RdxDesc, *StartV, CM.isInLoopReduction(Phi),
CM.useOrderedReductions(RdxDesc), ScaleFactor);
@@ -8840,7 +8839,7 @@ VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
if (isa<LoadInst>(Instr) || isa<StoreInst>(Instr))
return tryToWidenMemory(Instr, Operands, Range);
- if (getScaledReductionForInstr(Instr))
+ if (getScalingForReduction(Instr))
return tryToCreatePartialReduction(Instr, Operands);
if (!shouldWiden(Instr, Range))
diff --git a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
index cf653e2d3e6584..44745bfd46f891 100644
--- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
+++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
@@ -86,10 +86,8 @@ class VPRecipeBuilder {
/// created.
SmallVector<VPHeaderPHIRecipe *, 4> PhisToFix;
- /// The set of reduction exit instructions that will be scaled to
- /// a smaller VF via partial reductions, paired with the scaling factor.
- DenseMap<const Instruction *, std::pair<PartialReductionChain, unsigned>>
- ScaledReductionExitInstrs;
+ /// A mapping of partial reduction exit instructions to their scaling factor.
+ DenseMap<const Instruction *, unsigned> ScaledReductionMap;
/// Check if \p I can be widened at the start of \p Range and possibly
/// decrease the range such that the returned value holds for the entire \p
@@ -157,12 +155,10 @@ class VPRecipeBuilder {
: Plan(Plan), OrigLoop(OrigLoop), TLI(TLI), TTI(TTI), Legal(Legal),
CM(CM), PSE(PSE), Builder(Builder) {}
- std::optional<std::pair<PartialReductionChain, unsigned>>
- getScaledReductionForInstr(const Instruction *ExitInst) {
- auto It = ScaledReductionExitInstrs.find(ExitInst);
- return It == ScaledReductionExitInstrs.end()
- ? std::nullopt
- : std::make_optional(It->second);
+ std::optional<unsigned> getScalingForReduction(const Instruction *ExitInst) {
+ auto It = ScaledReductionMap.find(ExitInst);
+ return It == ScaledReductionMap.end() ? std::nullopt
+ : std::make_optional(It->second);
}
/// Find all possible partial reductions in the loop and track all of those
More information about the llvm-commits
mailing list