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

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 24 04:27:04 PDT 2024


================
@@ -9019,9 +9118,29 @@ 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 (BasicBlock *BB : make_range(DFS.beginRPO(), DFS.endRPO())) {
----------------
huntergr-arm wrote:

There's no need to iterate over (nearly) all instructions in the loop if you're just interested in the reductions -- `Legal->getReductionVars()` can be iterated over and will provide you with pairs of `PHINode *` and `RecurrenceDescriptor`.

e.g.
`for (const auto &[Phi, RdxDesc] : Legal->getReductionVars())`

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


More information about the llvm-commits mailing list