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

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 05:01:41 PDT 2024


================
@@ -9019,6 +9120,17 @@ 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()) {
+    std::optional<PartialReductionChain> Chain =
----------------
huntergr-arm wrote:

```suggestion
    if (auto Chain = getScaledReduction(Phi, RdxDesc, &TTI, Range, CM))
      Plan->addScaledReductionExitInstr(*Chain);
```
You can then remove the {} as well.

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


More information about the llvm-commits mailing list