Fix a problem where shifting by 64-bits leads to incorrect results on PPC
authorReid Spencer <rspencer@reidspencer.com>
Fri, 2 Mar 2007 01:19:42 +0000 (01:19 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Fri, 2 Mar 2007 01:19:42 +0000 (01:19 +0000)
but not on X86 becuase shift by word size is "undefined".

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

lib/Support/APInt.cpp

index 9b000da0ee39eab2ba5fecae1a07182728055d19..36f88a24798d48452d62a73a9ead563c613139e0 100644 (file)
@@ -938,7 +938,10 @@ APInt &APInt::sext(uint32_t width) {
   if (wordsBefore == wordsAfter) {
     uint32_t newWordBits = width % APINT_BITS_PER_WORD;
     // The extension is contained to the wordsBefore-1th word.
-    uint64_t mask = (~0ULL >> (APINT_BITS_PER_WORD - newWordBits)) <<  wordBits;
+    uint64_t mask = ~0ULL;
+    if (newWordBits)
+      mask >>= APINT_BITS_PER_WORD - newWordBits;
+    mask <<= wordBits;
     if (wordsBefore == 1)
       VAL |= mask;
     else