@@ -3695,6 +3695,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
36953695 SDValue N0 = N->getOperand(0);
36963696 SDValue N1 = N->getOperand(1);
36973697 EVT VT = N0.getValueType();
3698+ unsigned BitWidth = VT.getScalarSizeInBits();
36983699 SDLoc DL(N);
36993700
37003701 auto PeekThroughFreeze = [](SDValue N) {
@@ -3731,7 +3732,6 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
37313732 DAG.getConstant(-N1C->getAPIntValue(), DL, VT));
37323733
37333734 if (isNullOrNullSplat(N0)) {
3734- unsigned BitWidth = VT.getScalarSizeInBits();
37353735 // Right-shifting everything out but the sign bit followed by negation is
37363736 // the same as flipping arithmetic/logical shift type without the negation:
37373737 // -(X >>u 31) -> (X >>s 31)
@@ -3931,7 +3931,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
39313931 SDValue S0 = N1.getOperand(0);
39323932 if ((X0 == S0 && X1 == N1) || (X0 == N1 && X1 == S0))
39333933 if (ConstantSDNode *C = isConstOrConstSplat(N1.getOperand(1)))
3934- if (C->getAPIntValue() == (VT.getScalarSizeInBits() - 1))
3934+ if (C->getAPIntValue() == (BitWidth - 1))
39353935 return DAG.getNode(ISD::ABS, SDLoc(N), VT, S0);
39363936 }
39373937 }
@@ -3974,8 +3974,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
39743974 if (!LegalOperations && N1.getOpcode() == ISD::SRL && N1.hasOneUse()) {
39753975 SDValue ShAmt = N1.getOperand(1);
39763976 ConstantSDNode *ShAmtC = isConstOrConstSplat(ShAmt);
3977- if (ShAmtC &&
3978- ShAmtC->getAPIntValue() == (N1.getScalarValueSizeInBits() - 1)) {
3977+ if (ShAmtC && ShAmtC->getAPIntValue() == (BitWidth - 1)) {
39793978 SDValue SRA = DAG.getNode(ISD::SRA, DL, VT, N1.getOperand(0), ShAmt);
39803979 return DAG.getNode(ISD::ADD, DL, VT, N0, SRA);
39813980 }
@@ -3986,7 +3985,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
39863985 // N0 - (X << BW-1) --> N0 + (X << BW-1)
39873986 if (N1.getOpcode() == ISD::SHL) {
39883987 ConstantSDNode *ShlC = isConstOrConstSplat(N1.getOperand(1));
3989- if (ShlC && ShlC->getAPIntValue() == VT.getScalarSizeInBits() - 1)
3988+ if (ShlC && ShlC->getAPIntValue() == (BitWidth - 1) )
39903989 return DAG.getNode(ISD::ADD, DL, VT, N1, N0);
39913990 }
39923991
0 commit comments