[llvm-branch-commits] [llvm] [LV] Use VPReductionRecipe for partial reductions (PR #146073)
Sander de Smalen via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jul 1 02:08:42 PDT 2025
================
@@ -2744,6 +2702,12 @@ class VPSingleDefBundleRecipe : public VPSingleDefRecipe {
/// vector operands, performing a reduction.add on the result, and adding
/// the scalar result to a chain.
MulAccumulateReduction,
+ /// Represent an inloop multiply-accumulate reduction, multiplying the
+ /// extended vector operands, negating the multiplication, performing a
+ /// reduction.add
+ /// on the result, and adding
+ /// the scalar result to a chain.
+ ExtNegatedMulAccumulateReduction,
----------------
sdesmalen-arm wrote:
This looks like something that is currently not yet supported for InLoop reductions. Because you're trying to align the PartialReductions with other reductions, we need to add support for `sub` reductions as well to InLoop reductions. I'd suggest pulling that out into a separate PR (and rebasing this one on top of that).
This will require a few changes:
* `RecurrenceDescriptor::getReductionOpChain` does not recognise sub-reductions at the moment, which will need fixing. The reason for that is described in one of the comments:
```
// [..] Subs are also currently not allowed (which are usually
// treated as part of a add reduction) as they are expected to generally be
// more expensive than out-of-loop reductions, and need to be costed more
// carefully.
```
Because you're adding a cost-model for those here, we can now handle sub-reductions as well.
* When the `VPReductionRecipe` is created in `LoopVectorizationPlanner::adjustRecipesForReductions`, for in-loop sub-reductions we'd need to add a `sub(0, VecOp)` similar to how we do this for partial reductions.
When we finally properly merge the two implementations, the special code we currently have for partial reductions to insert the `sub` can be removed, in favour of the code that we'd need to add for in-loop reductions. (FWIW, that is not something I'm suggesting to do as part of this PR, but rather as a future follow-up)
https://github.com/llvm/llvm-project/pull/146073
More information about the llvm-branch-commits
mailing list