]> granicus.if.org Git - llvm/commitdiff
[APInt] Cleanup the reverseBits slow case a little.
authorCraig Topper <craig.topper@gmail.com>
Tue, 18 Apr 2017 05:02:21 +0000 (05:02 +0000)
committerCraig Topper <craig.topper@gmail.com>
Tue, 18 Apr 2017 05:02:21 +0000 (05:02 +0000)
Use lshrInPlace. Use single bit extract and operator|=(uint64_t) to avoid a few temporary APInts.

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

lib/Support/APInt.cpp

index 1094a61cf1cbb0a6f9f448374efa8fa544f45bae..5ac98e1c127fe8855cb9780e22c2d652d565fa9d 100644 (file)
@@ -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;
   }