[llvm] r300798 - [APInt] Don't call getActiveBits() in ult/ugt(uint64_t) if its a single word.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 19 16:55:48 PDT 2017


Author: ctopper
Date: Wed Apr 19 18:55:48 2017
New Revision: 300798

URL: http://llvm.org/viewvc/llvm-project?rev=300798&view=rev
Log:
[APInt] Don't call getActiveBits() in ult/ugt(uint64_t) if its a single word.

The compiled code already needs to check single/multi word for the countLeadingZeros call inside of getActiveBits, but it isn't able to optimize out the leadingZeros call in the single word case that can't produce a value larger than 64.

This shrank the opt binary by about 5-6k on my local x86-64 build.



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=300798&r1=300797&r2=300798&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Wed Apr 19 18:55:48 2017
@@ -1083,7 +1083,8 @@ public:
   ///
   /// \returns true if *this < RHS when considered unsigned.
   bool ult(uint64_t RHS) const {
-    return getActiveBits() > 64 ? false : getZExtValue() < RHS;
+    // Only need to check active bits if not a single word.
+    return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() < RHS;
   }
 
   /// \brief Signed less than comparison
@@ -1151,7 +1152,8 @@ public:
   ///
   /// \returns true if *this > RHS when considered unsigned.
   bool ugt(uint64_t RHS) const {
-    return getActiveBits() > 64 ? true : getZExtValue() > RHS;
+    // Only need to check active bits if not a single word.
+    return (!isSingleWord() && getActiveBits() > 64) || getZExtValue() > RHS;
   }
 
   /// \brief Signed greather than comparison




More information about the llvm-commits mailing list