[llvm] 34ad4cc - [APInt] byteSwap - simplify sub 64-bits cases to match general implementation. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 15 04:16:38 PST 2020


Author: Simon Pilgrim
Date: 2020-02-15T12:16:14Z
New Revision: 34ad4cca7245626c3d8348c7e3dd077ff35db84e

URL: https://github.com/llvm/llvm-project/commit/34ad4cca7245626c3d8348c7e3dd077ff35db84e
DIFF: https://github.com/llvm/llvm-project/commit/34ad4cca7245626c3d8348c7e3dd077ff35db84e.diff

LOG: [APInt] byteSwap - simplify sub 64-bits cases to match general implementation. NFCI.

We can just byteSwap the entire uint64_t VAL and then shift down into place like we do for the multi-word case.

Added: 
    

Modified: 
    llvm/lib/Support/APInt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index c07fc6d2279b..3a5fada6cf66 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -675,15 +675,11 @@ APInt APInt::byteSwap() const {
     return APInt(BitWidth, ByteSwap_16(uint16_t(U.VAL)));
   if (BitWidth == 32)
     return APInt(BitWidth, ByteSwap_32(unsigned(U.VAL)));
-  if (BitWidth == 48) {
-    unsigned Tmp1 = unsigned(U.VAL >> 16);
-    Tmp1 = ByteSwap_32(Tmp1);
-    uint16_t Tmp2 = uint16_t(U.VAL);
-    Tmp2 = ByteSwap_16(Tmp2);
-    return APInt(BitWidth, (uint64_t(Tmp2) << 32) | Tmp1);
-  }
-  if (BitWidth == 64)
-    return APInt(BitWidth, ByteSwap_64(U.VAL));
+  if (BitWidth <= 64) {
+    uint64_t Tmp1 = ByteSwap_64(U.VAL);
+    Tmp1 >>= (64 - BitWidth);
+    return APInt(BitWidth, Tmp1);
+  }
 
   APInt Result(getNumWords() * APINT_BITS_PER_WORD, 0);
   for (unsigned I = 0, N = getNumWords(); I != N; ++I)


        


More information about the llvm-commits mailing list