[llvm] [SelectionDAG] Fold VECREDUCE_ADD of a constant BUILD_VECTOR (PR #207560)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 5 01:11:13 PDT 2026
================
@@ -7797,6 +7786,23 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
// Early-out if we failed to constant fold a bitcast.
if (Opcode == ISD::BITCAST)
return SDValue();
+
+ // Constant fold VECREDUCE_ADD with a BUILD_VECTOR of integer constants.
+ if (Opcode == ISD::VECREDUCE_ADD && N1.getOpcode() == ISD::BUILD_VECTOR &&
+ ISD::isBuildVectorOfConstantSDNodes(N1.getNode())) {
+ unsigned EltBits = N1.getValueType().getScalarSizeInBits();
+ APInt Acc = APInt::getZero(EltBits);
+ bool HasUndef = false;
+ for (SDValue Elt : N1->op_values()) {
+ if (Elt.isUndef() || cast<ConstantSDNode>(Elt)->isOpaque()) {
+ HasUndef = true;
----------------
RKSimon wrote:
just return SDValue() here?
https://github.com/llvm/llvm-project/pull/207560
More information about the llvm-commits
mailing list