summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-05-12 21:45:44 +0000
committerCraig Topper <craig.topper@gmail.com>2017-05-12 21:45:44 +0000
commit2579c7c69f08330951d947c51f6f6938f0fdc737 (patch)
tree97ed8f03083fd7ae8f71783fb8058f8089e1fbe1 /llvm/lib/Support/APInt.cpp
parent1fa362f8119cab531de85c580a558fa520acc255 (diff)
downloadbcm5719-llvm-2579c7c69f08330951d947c51f6f6938f0fdc737.tar.gz
bcm5719-llvm-2579c7c69f08330951d947c51f6f6938f0fdc737.zip
[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. llvm-svn: 302952
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index f4aa627d6ce..25d39771a08 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -1648,14 +1648,15 @@ APInt APInt::srem(const APInt &RHS) const {
void APInt::udivrem(const APInt &LHS, const APInt &RHS,
APInt &Quotient, APInt &Remainder) {
assert(LHS.BitWidth == RHS.BitWidth && "Bit widths must be the same");
+ unsigned BitWidth = LHS.BitWidth;
// First, deal with the easy case
if (LHS.isSingleWord()) {
assert(RHS.U.VAL != 0 && "Divide by zero?");
uint64_t QuotVal = LHS.U.VAL / RHS.U.VAL;
uint64_t RemVal = LHS.U.VAL % RHS.U.VAL;
- Quotient = APInt(LHS.BitWidth, QuotVal);
- Remainder = APInt(LHS.BitWidth, RemVal);
+ Quotient = APInt(BitWidth, QuotVal);
+ Remainder = APInt(BitWidth, RemVal);
return;
}
@@ -1688,8 +1689,8 @@ void APInt::udivrem(const APInt &LHS, const APInt &RHS,
uint64_t lhsValue = LHS.U.pVal[0];
uint64_t rhsValue = RHS.U.pVal[0];
// Make sure there is enough space to hold the results.
- Quotient.reallocate(LHS.BitWidth);
- Remainder.reallocate(LHS.BitWidth);
+ Quotient.reallocate(BitWidth);
+ Remainder.reallocate(BitWidth);
Quotient = lhsValue / rhsValue;
Remainder = lhsValue % rhsValue;
return;
OpenPOWER on IntegriCloud