return SDValue();
SDValue ScalarV = Reduce.getOperand(2);
+ EVT ScalarVT = ScalarV.getValueType();
if (ScalarV.getOpcode() == ISD::INSERT_SUBVECTOR &&
ScalarV.getOperand(0)->isUndef())
ScalarV = ScalarV.getOperand(1);
SDValue NewStart = N->getOperand(1 - ReduceIdx);
+ SDLoc DL(N);
SDValue NewScalarV =
- lowerScalarInsert(NewStart, ScalarV.getOperand(2), ScalarV.getSimpleValueType(),
- SDLoc(N), DAG, Subtarget);
+ lowerScalarInsert(NewStart, ScalarV.getOperand(2),
+ ScalarV.getSimpleValueType(), DL, DAG, Subtarget);
+
+ // If we looked through an INSERT_SUBVECTOR we need to restore it.
+ if (ScalarVT != ScalarV.getValueType())
+ NewScalarV =
+ DAG.getNode(ISD::INSERT_SUBVECTOR, DL, ScalarVT, DAG.getUNDEF(ScalarVT),
+ NewScalarV, DAG.getConstant(0, DL, Subtarget.getXLenVT()));
+
SDValue NewReduce =
- DAG.getNode(Reduce.getOpcode(), SDLoc(Reduce), Reduce.getValueType(),
+ DAG.getNode(Reduce.getOpcode(), DL, Reduce.getValueType(),
Reduce.getOperand(0), Reduce.getOperand(1), NewScalarV,
Reduce.getOperand(3), Reduce.getOperand(4));
- return DAG.getNode(Extract.getOpcode(), SDLoc(Extract),
- Extract.getValueType(), NewReduce, Extract.getOperand(1));
+ return DAG.getNode(Extract.getOpcode(), DL, Extract.getValueType(), NewReduce,
+ Extract.getOperand(1));
}
// Optimize (add (shl x, c0), (shl y, c1)) ->