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

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 03:20:43 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();
----------------
huntergr-arm wrote:

I think you could add Chain instances to a local SmallVector here, then pass that to a single interface in RecipeBuilder which filtered the results and only stored it to the ScaledReductionExitInstrs map if there were no additional uses.

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


More information about the llvm-commits mailing list