[APInt] Optimize APInt creation from uint64_t
authorCraig Topper <craig.topper@gmail.com>
Wed, 1 Mar 2017 21:06:18 +0000 (21:06 +0000)
committerCraig Topper <craig.topper@gmail.com>
Wed, 1 Mar 2017 21:06:18 +0000 (21:06 +0000)
Summary:
This patch moves the clearUnusedBits calls into the two different initialization paths for APInt from a uint64_t. This allows the compiler to better optimize the clearing of the unused bits for the single word case. And it puts the clearing for the multi word case into the initSlowCase function to save code. In the common case of initializing with 0 this allows the clearing to be completely optimized out for the single word case.

On my local x86 build this is showing a ~45kb reduction in the size of the opt binary.

Reviewers: RKSimon, hans, majnemer, davide, MatzeB

Reviewed By: hans

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D30486

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296677 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h
lib/Support/APInt.cpp

index 2af3aabe1881085e0736f0fd4f30e0606156930f..2acb60f769d45448469a5f602eb6b8d95cde2146 100644 (file)
@@ -240,11 +240,12 @@ public:
   APInt(unsigned numBits, uint64_t val, bool isSigned = false)
       : BitWidth(numBits), VAL(0) {
     assert(BitWidth && "bitwidth too small");
-    if (isSingleWord())
+    if (isSingleWord()) {
       VAL = val;
-    else
+      clearUnusedBits();
+    } else {
       initSlowCase(val, isSigned);
-    clearUnusedBits();
+    }
   }
 
   /// \brief Construct an APInt of numBits width, initialized as bigVal[].
index 10124fabaec870ca7eba49d00757d1d75def7170..836498e6c0eae5c8e9f886aef16ff397991c6bc3 100644 (file)
@@ -81,6 +81,7 @@ void APInt::initSlowCase(uint64_t val, bool isSigned) {
   if (isSigned && int64_t(val) < 0)
     for (unsigned i = 1; i < getNumWords(); ++i)
       pVal[i] = -1ULL;
+  clearUnusedBits();
 }
 
 void APInt::initSlowCase(const APInt& that) {