[llvm] r301842 - [APInt] In operator!, handle single word case by comparing VAL to 0 directly and handle multiword case by comparing countLeadingZerosSlowCase() to BitWidth.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon May 1 14:56:05 PDT 2017


Author: ctopper
Date: Mon May  1 16:56:05 2017
New Revision: 301842

URL: http://llvm.org/viewvc/llvm-project?rev=301842&view=rev
Log:
[APInt] In operator!, handle single word case by comparing VAL to 0 directly and handle multiword case by comparing countLeadingZerosSlowCase() to BitWidth.

We were using operator=(0) which implicitly calls countLeadingZeros but only to compare with 64 to determine if we can compare VAL or pVal[0] to uint64_t. By handling the multiword case with countLeadingZerosSlowCase==BitWidth we can prevent a load of pVal[0] from being inserted inline at each call site. This saves a little bit of code size.

Modified:
    llvm/trunk/include/llvm/ADT/APInt.h

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=301842&r1=301841&r2=301842&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Mon May  1 16:56:05 2017
@@ -693,7 +693,9 @@ public:
   ///
   /// \returns true if *this is zero, false otherwise.
   bool operator!() const {
-    return *this == 0;
+    if (isSingleWord())
+      return VAL == 0;
+    return countLeadingZerosSlowCase() == BitWidth;
   }
 
   /// @}




More information about the llvm-commits mailing list