diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -23498,6 +23498,16 @@ return DAG.getNode(Opcode, SDLoc(N), N->getValueType(0), Subvec); } + // fold vecreduce_or/and(splat_vector(val)) -> constant val + // fold vecreduce_xor(splat_vector(val)) -> constant zero + APInt SplatVal; + if (ISD::isConstantSplatVector(N0.getNode(), SplatVal)) { + if (Opcode == ISD::VECREDUCE_XOR) + return DAG.getConstant(0, SDLoc(N), N->getValueType(0)); + if (Opcode == ISD::VECREDUCE_AND || Opcode == ISD::VECREDUCE_OR) + return DAG.getConstant(SplatVal, SDLoc(N), N->getValueType(0)); + } + return SDValue(); }