@@ -13859,43 +13859,30 @@ static SDValue getMad64_32(SelectionDAG &DAG, const SDLoc &SL, EVT VT,
1385913859
1386013860// Fold
1386113861// y = lshr i64 x, 32
13862- // res = add (mul i64 y, Constant ), x where "Constant " is a 32 bit
13863- // negative value
13862+ // res = add (mul i64 y, Const ), x where "Const " is a 64- bit constant
13863+ // with Const.hi == -1
1386413864// To
13865- // res = mad_u64_u32 y.lo ,Constant .lo, x.lo
13865+ // res = mad_u64_u32 y.lo ,Const .lo, x.lo
1386613866static SDValue tryFoldMADwithSRL(SelectionDAG &DAG, const SDLoc &SL,
1386713867 SDValue MulLHS, SDValue MulRHS,
1386813868 SDValue AddRHS) {
1386913869
13870- if (MulLHS.getValueType() != MVT::i64)
13870+ if (MulLHS.getValueType() != MVT::i64 || MulLHS.getOpcode() != ISD::SRL )
1387113871 return SDValue();
1387213872
13873- ConstantSDNode *ConstOp;
13874- SDValue ShiftOp;
13875- if (MulLHS.getOpcode() == ISD::SRL && MulRHS.getOpcode() == ISD::Constant) {
13876- ConstOp = cast<ConstantSDNode>(MulRHS.getNode());
13877- ShiftOp = MulLHS;
13878- } else if (MulRHS.getOpcode() == ISD::SRL &&
13879- MulLHS.getOpcode() == ISD::Constant) {
13880- ConstOp = cast<ConstantSDNode>(MulLHS.getNode());
13881- ShiftOp = MulRHS;
13882- } else
13883- return SDValue();
13884-
13885- if (ShiftOp.getOperand(1).getOpcode() != ISD::Constant ||
13886- AddRHS != ShiftOp.getOperand(0))
13873+ if (MulLHS.getOperand(1).getOpcode() != ISD::Constant ||
13874+ MulLHS.getOperand(0) != AddRHS)
1388713875 return SDValue();
1388813876
13889- if (cast<ConstantSDNode>(ShiftOp ->getOperand(1))->getAsZExtVal() != 32)
13877+ if (cast<ConstantSDNode>(MulLHS ->getOperand(1))->getAsZExtVal() != 32)
1389013878 return SDValue();
1389113879
13892- APInt ConstVal = ConstOp ->getAPIntValue();
13893- if (!ConstVal .isNegative() || !ConstVal .isSignedIntN(33))
13880+ APInt Const = cast<ConstantSDNode>(MulRHS.getNode()) ->getAPIntValue();
13881+ if (!Const .isNegative() || !Const .isSignedIntN(33))
1389413882 return SDValue();
1389513883
13896- SDValue Zero = DAG.getConstant(0, SL, MVT::i32);
13897- SDValue ConstMul = DAG.getConstant(
13898- ConstVal.getZExtValue() & 0x00000000FFFFFFFF, SL, MVT::i32);
13884+ SDValue ConstMul =
13885+ DAG.getConstant(Const.getZExtValue() & 0x00000000FFFFFFFF, SL, MVT::i32);
1389913886 AddRHS = DAG.getNode(ISD::AND, SL, MVT::i64, AddRHS,
1390013887 DAG.getConstant(0x00000000FFFFFFFF, SL, MVT::i64));
1390113888 return getMad64_32(DAG, SL, MVT::i64,
@@ -13961,8 +13948,14 @@ SDValue SITargetLowering::tryFoldToMad64_32(SDNode *N,
1396113948 SDValue MulRHS = LHS.getOperand(1);
1396213949 SDValue AddRHS = RHS;
1396313950
13964- if (SDValue FoldedMAD = tryFoldMADwithSRL(DAG, SL, MulLHS, MulRHS, AddRHS))
13965- return FoldedMAD;
13951+ if (MulLHS.getOpcode() == ISD::Constant ||
13952+ MulRHS.getOpcode() == ISD::Constant) {
13953+ if (MulRHS.getOpcode() == ISD::SRL)
13954+ std::swap(MulLHS, MulRHS);
13955+
13956+ if (SDValue FoldedMAD = tryFoldMADwithSRL(DAG, SL, MulLHS, MulRHS, AddRHS))
13957+ return FoldedMAD;
13958+ }
1396613959
1396713960 // Always check whether operands are small unsigned values, since that
1396813961 // knowledge is useful in more cases. Check for small signed values only if
0 commit comments