diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index f6f80db58cf1b..29f3940ed6fa7 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> 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(Instr) || isa(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 cf653e2d3e658..44745bfd46f89 100644 --- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h +++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h @@ -86,10 +86,8 @@ class VPRecipeBuilder { /// created. SmallVector PhisToFix; - /// The set of reduction exit instructions that will be scaled to - /// a smaller VF via partial reductions, paired with the scaling factor. - DenseMap> - ScaledReductionExitInstrs; + /// A mapping of partial reduction exit instructions to their scaling factor. + DenseMap 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> - getScaledReductionForInstr(const Instruction *ExitInst) { - auto It = ScaledReductionExitInstrs.find(ExitInst); - return It == ScaledReductionExitInstrs.end() - ? std::nullopt - : std::make_optional(It->second); + std::optional 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