[RISCV] Strengthen INSERT_SUBVECTOR check in combineBinOpToReduce.
authorCraig Topper <craig.topper@sifive.com>
Tue, 25 Apr 2023 00:30:35 +0000 (17:30 -0700)
committerCraig Topper <craig.topper@sifive.com>
Tue, 25 Apr 2023 00:41:09 +0000 (17:41 -0700)
It's not enough for the vector we're inserting into to be undef.
We also need to be inserting into the lowest subvector.

Spotted by inspection while trying to figure out why this doesn't
work for vp.reduce.fadd.

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

index d23d496..897a8a6 100644 (file)
@@ -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.