Implement extension of sign bits for negative values in the uint64_t
authorReid Spencer <rspencer@reidspencer.com>
Mon, 19 Mar 2007 20:37:47 +0000 (20:37 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Mon, 19 Mar 2007 20:37:47 +0000 (20:37 +0000)
constructor. This helps to fix test/Assembler/2007-03-19-NegValue.ll

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

lib/Support/APInt.cpp

index 08ec2362007bb054d6970c1fc268814fe57b717c..0d0f9ffca49a0e44573e0b0f0907e5a18c4b32f4 100644 (file)
@@ -43,7 +43,8 @@ inline static uint64_t* getMemory(uint32_t numWords) {
   return result;
 }
 
-APInt::APInt(uint32_t numBits, uint64_t val) : BitWidth(numBits), VAL(0) {
+APInt::APInt(uint32_t numBits, uint64_t val, bool isSigned ) 
+  : BitWidth(numBits), VAL(0) {
   assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
   assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
   if (isSingleWord())
@@ -51,6 +52,9 @@ APInt::APInt(uint32_t numBits, uint64_t val) : BitWidth(numBits), VAL(0) {
   else {
     pVal = getClearedMemory(getNumWords());
     pVal[0] = val;
+    if (isSigned && int64_t(val) < 0) 
+      for (unsigned i = 1; i < getNumWords(); ++i)
+        pVal[i] = -1ULL;
   }
   clearUnusedBits();
 }