@@ -12406,9 +12406,13 @@ static SDValue tryFoldSelectIntoOp(SDNode *N, SelectionDAG &DAG,
12406
12406
SDValue TrueVal, SDValue FalseVal,
12407
12407
bool Swapped) {
12408
12408
bool Commutative = true;
12409
- switch (TrueVal.getOpcode()) {
12409
+ unsigned Opc = TrueVal.getOpcode();
12410
+ switch (Opc) {
12410
12411
default:
12411
12412
return SDValue();
12413
+ case ISD::SHL:
12414
+ case ISD::SRA:
12415
+ case ISD::SRL:
12412
12416
case ISD::SUB:
12413
12417
Commutative = false;
12414
12418
break;
@@ -12431,12 +12435,18 @@ static SDValue tryFoldSelectIntoOp(SDNode *N, SelectionDAG &DAG,
12431
12435
12432
12436
EVT VT = N->getValueType(0);
12433
12437
SDLoc DL(N);
12434
- SDValue Zero = DAG.getConstant(0, DL, VT);
12435
12438
SDValue OtherOp = TrueVal.getOperand(1 - OpToFold);
12439
+ EVT OtherOpVT = OtherOp->getValueType(0);
12440
+ SDValue IdentityOperand =
12441
+ DAG.getNeutralElement(Opc, DL, OtherOpVT, N->getFlags());
12442
+ if (!Commutative)
12443
+ IdentityOperand = DAG.getConstant(0, DL, OtherOpVT);
12444
+ assert(IdentityOperand && "No identity operand!");
12436
12445
12437
12446
if (Swapped)
12438
- std::swap(OtherOp, Zero);
12439
- SDValue NewSel = DAG.getSelect(DL, VT, N->getOperand(0), OtherOp, Zero);
12447
+ std::swap(OtherOp, IdentityOperand);
12448
+ SDValue NewSel =
12449
+ DAG.getSelect(DL, OtherOpVT, N->getOperand(0), OtherOp, IdentityOperand);
12440
12450
return DAG.getNode(TrueVal.getOpcode(), DL, VT, FalseVal, NewSel);
12441
12451
}
12442
12452
0 commit comments