diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index d23d4962eb833..897a8a69142a4 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -9126,7 +9126,8 @@ static SDValue combineBinOpToReduce(SDNode *N, SelectionDAG &DAG, SDValue ScalarV = Reduce.getOperand(2); EVT ScalarVT = ScalarV.getValueType(); if (ScalarV.getOpcode() == ISD::INSERT_SUBVECTOR && - ScalarV.getOperand(0)->isUndef()) + ScalarV.getOperand(0)->isUndef() && + isNullConstant(ScalarV.getOperand(2))) ScalarV = ScalarV.getOperand(1); // Make sure that ScalarV is a splat with VL=1.