llvm-project
bc495da8 - [SelectionDAG] Fold constant PARTIAL_REDUCE_SMLA/UMLA/SUMLA nodes (#210351)

Commit
78 days ago
[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
Author
Parents
Loading