[llvm] [LoopVectorizer] Add support for partial reductions (PR #92418)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 09:32:31 PST 2024


================
@@ -9019,6 +9152,15 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
         bool NeedsBlends = BB != HeaderBB && !BB->phis().empty();
         return Legal->blockNeedsPredication(BB) || NeedsBlends;
       });
+
+  // Cache the partial reductions up front so we can remove the invalid ones
+  // before creating the recipes
+  for (const auto &[Phi, RdxDesc] : Legal->getReductionVars())
+    if (std::optional<PartialReductionChain> Chain =
+            getScaledReduction(Phi, RdxDesc, &TTI, Range, CM))
+      RecipeBuilder.addScaledReductionExitInstr(*Chain);
+  RecipeBuilder.removeInvalidScaledReductionExitInstrs();
----------------
SamTebbs33 wrote:

Ah I like that idea Graham, since it is a bit more efficient than adding then removing. I've tried that approach but will keep Florian's suggestion in mind if you don't like how it's been done.

https://github.com/llvm/llvm-project/pull/92418


More information about the llvm-commits mailing list