llvm.org GIT mirror llvm / d2329ac
[APInt] In udivrem, remember the bit width in a local variable so we don't reread it from the LHS which might be aliased with Quotient or Remainder. This helped the compiler generate better code for the single word case. It was able to remember that the bit width was still a single word when it created the Remainder APInt and not create code for it possibly being multiword. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302952 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 3 years ago
1 changed file(s) with 5 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
16471647 void APInt::udivrem(const APInt &LHS, const APInt &RHS,
16481648 APInt &Quotient, APInt &Remainder) {
16491649 assert(LHS.BitWidth == RHS.BitWidth && "Bit widths must be the same");
1650 unsigned BitWidth = LHS.BitWidth;
16501651
16511652 // First, deal with the easy case
16521653 if (LHS.isSingleWord()) {
16531654 assert(RHS.U.VAL != 0 && "Divide by zero?");
16541655 uint64_t QuotVal = LHS.U.VAL / RHS.U.VAL;
16551656 uint64_t RemVal = LHS.U.VAL % RHS.U.VAL;
1656 Quotient = APInt(LHS.BitWidth, QuotVal);
1657 Remainder = APInt(LHS.BitWidth, RemVal);
1657 Quotient = APInt(BitWidth, QuotVal);
1658 Remainder = APInt(BitWidth, RemVal);
16581659 return;
16591660 }
16601661
16871688 uint64_t lhsValue = LHS.U.pVal[0];
16881689 uint64_t rhsValue = RHS.U.pVal[0];
16891690 // Make sure there is enough space to hold the results.
1690 Quotient.reallocate(LHS.BitWidth);
1691 Remainder.reallocate(LHS.BitWidth);
1691 Quotient.reallocate(BitWidth);
1692 Remainder.reallocate(BitWidth);
16921693 Quotient = lhsValue / rhsValue;
16931694 Remainder = lhsValue % rhsValue;
16941695 return;