[llvm] r298858 - [APInt] Move the >64 bit case for flipAllBits out of line.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 27 10:10:21 PDT 2017


Author: ctopper
Date: Mon Mar 27 12:10:21 2017
New Revision: 298858

URL: http://llvm.org/viewvc/llvm-project?rev=298858&view=rev
Log:
[APInt] Move the >64 bit case for flipAllBits out of line.

This is more consistent with what we do for other operations. This shrinks the opt binary on my build by ~72k.


Modified:
    llvm/trunk/include/llvm/ADT/APInt.h
    llvm/trunk/lib/Support/APInt.cpp

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=298858&r1=298857&r2=298858&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Mon Mar 27 12:10:21 2017
@@ -217,6 +217,9 @@ class LLVM_NODISCARD APInt {
   /// out-of-line slow case for setBits.
   void setBitsSlowCase(unsigned loBit, unsigned hiBit);
 
+  /// out-of-line slow case for flipAllBits.
+  void flipAllBitsSlowCase();
+
 public:
   /// \name Constructors
   /// @{
@@ -1233,13 +1236,12 @@ public:
 
   /// \brief Toggle every bit to its opposite value.
   void flipAllBits() {
-    if (isSingleWord())
+    if (isSingleWord()) {
       VAL ^= UINT64_MAX;
-    else {
-      for (unsigned i = 0; i < getNumWords(); ++i)
-        pVal[i] ^= UINT64_MAX;
+      clearUnusedBits();
+    } else {
+      flipAllBitsSlowCase();
     }
-    clearUnusedBits();
   }
 
   /// \brief Toggles a given bit to its opposite value.

Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=298858&r1=298857&r2=298858&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Mon Mar 27 12:10:21 2017
@@ -581,6 +581,11 @@ void APInt::clearBit(unsigned bitPositio
 }
 
 /// @brief Toggle every bit to its opposite value.
+void APInt::flipAllBitsSlowCase() {
+  for (unsigned i = 0; i < getNumWords(); ++i)
+    pVal[i] ^= UINT64_MAX;
+  clearUnusedBits();
+}
 
 /// Toggle a given bit to its opposite value whose position is given
 /// as "bitPosition".




More information about the llvm-commits mailing list