[llvm] r300527 - [APInt] Cleanup the reverseBits slow case a little.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 22:02:22 PDT 2017


Author: ctopper
Date: Tue Apr 18 00:02:21 2017
New Revision: 300527

URL: http://llvm.org/viewvc/llvm-project?rev=300527&view=rev
Log:
[APInt] Cleanup the reverseBits slow case a little.

Use lshrInPlace. Use single bit extract and operator|=(uint64_t) to avoid a few temporary APInts.

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=300527&r1=300526&r2=300527&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Tue Apr 18 00:02:21 2017
@@ -774,14 +774,12 @@ APInt APInt::reverseBits() const {
   }
 
   APInt Val(*this);
-  APInt Reversed(*this);
-  int S = BitWidth - 1;
+  APInt Reversed(BitWidth, 0);
+  unsigned S = BitWidth;
 
-  const APInt One(BitWidth, 1);
-
-  for ((Val = Val.lshr(1)); Val != 0; (Val = Val.lshr(1))) {
+  for (; Val != 0; Val.lshrInPlace(1)) {
     Reversed <<= 1;
-    Reversed |= (Val & One);
+    Reversed |= Val[0];
     --S;
   }
 




More information about the llvm-commits mailing list