[llvm] r302772 - [APInt] Remove an unneeded extra temporary APInt from toString.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 00:10:44 PDT 2017


Author: ctopper
Date: Thu May 11 02:10:43 2017
New Revision: 302772

URL: http://llvm.org/viewvc/llvm-project?rev=302772&view=rev
Log:
[APInt] Remove an unneeded extra temporary APInt from toString.

Turns out udivrem can write its output to the same location as one of its inputs so the extra temporary isn't needed.

Modified:
    llvm/trunk/lib/Support/APInt.cpp

Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=302772&r1=302771&r2=302772&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Thu May 11 02:10:43 2017
@@ -1953,15 +1953,11 @@ void APInt::toString(SmallVectorImpl<cha
   } else {
     APInt divisor(Tmp.getBitWidth(), Radix);
     APInt APdigit;
-    APInt tmp2(Tmp.getBitWidth(), 0);
     while (Tmp.getBoolValue()) {
-      udivrem(Tmp, divisor, tmp2, APdigit);
+      udivrem(Tmp, divisor, Tmp, APdigit);
       unsigned Digit = (unsigned)APdigit.getZExtValue();
       assert(Digit < Radix && "divide failed");
       Str.push_back(Digits[Digit]);
-      // Move the quotient into Tmp and move the old allocation of Tmp into
-      // tmp2 to be used on the next loop iteration.
-      std::swap(Tmp, tmp2);
     }
   }
 




More information about the llvm-commits mailing list