[all-commits] [llvm/llvm-project] bc495d: [SelectionDAG] Fold constant PARTIAL_REDUCE_SMLA/U...

Chennes via All-commits all-commits at lists.llvm.org
Fri Aug 7 04:19:04 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bc495da845041056e9a5892816d7fc214e371716
      https://github.com/llvm/llvm-project/commit/bc495da845041056e9a5892816d7fc214e371716
  Author: Chennes <xuchen359 at gmail.com>
  Date:   2026-08-07 (Fri, 07 Aug 2026)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    M llvm/test/CodeGen/RISCV/rvv/partial-reduction-add.ll
    M llvm/unittests/CodeGen/SelectionDAGNodeConstructionTest.cpp

  Log Message:
  -----------
  [SelectionDAG] Fold constant PARTIAL_REDUCE_SMLA/UMLA/SUMLA nodes (#210351)

This PR implements constant folding for `ISD::PARTIAL_REDUCE_SMLA`,
`ISD::PARTIAL_REDUCE_UMLA`, and `ISD::PARTIAL_REDUCE_SUMLA` when their
operands are constant `BUILD_VECTOR`s. The fold computes the partial
reduction using `APInt` arithmetic and returns a folded `BUILD_VECTOR`.

Input constants are truncated to their logical element width before
being sign- or zero-extended as required by each opcode. Input lane `I`
is accumulated into result lane `I % NumAccElts`, matching
`TargetLowering::expandPartialReduceMLA`. The reduction order is
deliberately unspecified, so this mapping is a valid refinement.

Poison is propagated only to the affected result lanes. Folding is
skipped for undef and opaque constants. Unsupported operand forms return
early because partial-reduce nodes have no scalar form and must not fall
through to generic per-element folding. After type legalization, when
the accumulator element type is not a legal scalar type, the folded
constants are created in the promoted legal type (matching the generic
per-lane folding path), and the fold bails out if legalization would
narrow the element type.

The RISC-V test precommits the existing codegen for the basic constant
fold. Additional IR tests cover accumulator-width wraparound, poison in
the input and accumulator, and safe handling of scalable splats. Direct
SelectionDAG unit tests are retained only for node forms that cannot be
reliably or acceptably tested through IR: the SMLA/UMLA/SUMLA signedness
matrix with promoted narrow inputs, promotion of the folded result to a
legal scalar type after type legalization, poison in the implicit
multiplier operand, undef and opaque elements, and partially constant
no-fold cases.

Fixes #209191



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