Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp +++ lib/Target/X86/X86ISelLowering.cpp @@ -24707,27 +24707,33 @@ ConstantSDNode *C = dyn_cast(N->getOperand(1)); if (!C) return SDValue(); - uint64_t MulAmt = C->getZExtValue(); - if (isPowerOf2_64(MulAmt) || MulAmt == 3 || MulAmt == 5 || MulAmt == 9) + APInt MulAmt = C->getAPIntValue(); + if (MulAmt.isPowerOf2() || MulAmt == 3 || MulAmt == 5 || MulAmt == 9) return SDValue(); - uint64_t MulAmt1 = 0; - uint64_t MulAmt2 = 0; - if ((MulAmt % 9) == 0) { - MulAmt1 = 9; - MulAmt2 = MulAmt / 9; - } else if ((MulAmt % 5) == 0) { - MulAmt1 = 5; - MulAmt2 = MulAmt / 5; - } else if ((MulAmt % 3) == 0) { - MulAmt1 = 3; - MulAmt2 = MulAmt / 3; - } - if (MulAmt2 && - (isPowerOf2_64(MulAmt2) || MulAmt2 == 3 || MulAmt2 == 5 || MulAmt2 == 9)){ + unsigned BitWidth = MulAmt.getBitWidth(); + APInt KnownZero = APInt(BitWidth, 0); + APInt KnownThree = APInt(BitWidth, 3); + APInt KnownFive = APInt(BitWidth, 5); + APInt KnownNine = APInt(BitWidth, 9); + + APInt MulAmt1 = KnownZero; + APInt MulAmt2 = KnownZero; + if (MulAmt.urem(KnownNine) == 0) { + MulAmt1 = KnownNine; + MulAmt2 = MulAmt.udiv(KnownNine); + } else if (MulAmt.urem(KnownFive) == 0) { + MulAmt1 = KnownFive; + MulAmt2 = MulAmt.udiv(KnownFive); + } else if (MulAmt.urem(KnownThree) == 0) { + MulAmt1 = KnownThree; + MulAmt2 = MulAmt.udiv(KnownThree); + } + if (MulAmt2 != 0 && + (MulAmt2.isPowerOf2() || MulAmt2 == 3 || MulAmt2 == 5 || MulAmt2 == 9)){ SDLoc DL(N); - if (isPowerOf2_64(MulAmt2) && + if (MulAmt2.isPowerOf2() && !(N->hasOneUse() && N->use_begin()->getOpcode() == ISD::ADD)) // If second multiplifer is pow2, issue it first. We want the multiply by // 3, 5, or 9 to be folded into the addressing mode unless the lone use @@ -24735,16 +24741,16 @@ std::swap(MulAmt1, MulAmt2); SDValue NewMul; - if (isPowerOf2_64(MulAmt1)) + if (MulAmt1.isPowerOf2()) NewMul = DAG.getNode(ISD::SHL, DL, VT, N->getOperand(0), - DAG.getConstant(Log2_64(MulAmt1), DL, MVT::i8)); + DAG.getConstant(MulAmt1.logBase2(), DL, MVT::i8)); else NewMul = DAG.getNode(X86ISD::MUL_IMM, DL, VT, N->getOperand(0), DAG.getConstant(MulAmt1, DL, VT)); - if (isPowerOf2_64(MulAmt2)) + if (MulAmt2.isPowerOf2()) NewMul = DAG.getNode(ISD::SHL, DL, VT, NewMul, - DAG.getConstant(Log2_64(MulAmt2), DL, MVT::i8)); + DAG.getConstant(MulAmt2.logBase2(), DL, MVT::i8)); else NewMul = DAG.getNode(X86ISD::MUL_IMM, DL, VT, NewMul, DAG.getConstant(MulAmt2, DL, VT));