[all-commits] [llvm/llvm-project] 315775: [LV] Handle partial sub-reductions with sub in mid...

Sander de Smalen via All-commits all-commits at lists.llvm.org
Tue Feb 10 03:00:54 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3157758190a487e344ecf1d2ff6402609a38d6b5
      https://github.com/llvm/llvm-project/commit/3157758190a487e344ecf1d2ff6402609a38d6b5
  Author: Sander de Smalen <sander.desmalen at arm.com>
  Date:   2026-02-10 (Tue, 10 Feb 2026)

  Changed paths:
    M llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
    M llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
    M llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-chained.ll
    A llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-sub-sdot.ll
    M llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-sub.ll

  Log Message:
  -----------
  [LV] Handle partial sub-reductions with sub in middle block. (#178919)

Sub-reductions can be implemented in two ways:
(1) negate the operand in the vector loop (the default way).
(2) subtract the reduced value from the init value in the middle block.

Note that both ways keep the reduction itself as an 'add' reduction,
which is necessary because only llvm.vector.partial.reduce.add exists.

The ISD nodes for partial reductions don't support folding the
sub/negation into its operands because the following is not a valid
transformation:
```
     sub(0, mul(ext(a), ext(b)))
  -> mul(ext(a), ext(sub(0, b)))
```
It can therefore be better to choose option (2) such that the partial
reduction is always positive (starting at '0') and to do a final
subtract in the middle block.

For AArch64 there are no dot-product instructions that can
do a `partial.reduce.sub(acc, mul(ext(a), ext(b)))` operation.
I'm not sure if such instructions exist for other targets.
(If so then we may want to make this decision a target option)

This PR also increases the AArch64 cost of a partial sub-reduction
when this exists in an 'add-sub' reduction chain.

Fixes https://github.com/llvm/llvm-project/issues/178703



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list