[llvm-commits] [llvm] r42210 - in /llvm/trunk: include/llvm/ADT/APInt.h lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/ExecutionEngine/ExecutionEngine.cpp lib/Support/APFloat.cpp lib/Support/APInt.cpp

Dale Johannesen dalej at apple.com
Fri Sep 21 15:09:37 PDT 2007


Author: johannes
Date: Fri Sep 21 17:09:37 2007
New Revision: 42210

URL: http://llvm.org/viewvc/llvm-project?rev=42210&view=rev
Log:
Change APFloat::convertFromInteger to take the incoming
bit width instead of number of words allocated, which
makes it actually work for int->APF conversions.
Adjust callers.  Add const to one of the APInt constructors
to prevent surprising match when called with const
argument.


Modified:
    llvm/trunk/include/llvm/ADT/APInt.h
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
    llvm/trunk/lib/Support/APFloat.cpp
    llvm/trunk/lib/Support/APInt.cpp

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=42210&r1=42209&r2=42210&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Fri Sep 21 17:09:37 2007
@@ -172,7 +172,7 @@
   /// @param numWords the number of words in bigVal
   /// @param bigVal a sequence of words to form the initial value of the APInt
   /// @brief Construct an APInt of numBits width, initialized as bigVal[].
-  APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[]);
+  APInt(uint32_t numBits, uint32_t numWords, const uint64_t bigVal[]);
 
   /// This constructor interprets Val as a string in the given radix. The 
   /// interpretation stops when the first charater that is not suitable for the

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=42210&r1=42209&r2=42210&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Fri Sep 21 17:09:37 2007
@@ -3215,7 +3215,8 @@
           const uint64_t zero[] = {0, 0};
           APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero));
           uint64_t x = 1ULL << ShiftAmt;
-          (void)apf.convertFromInteger(&x, 1, false, APFloat::rmTowardZero);
+          (void)apf.convertFromInteger(&x, MVT::getSizeInBits(NVT), false, 
+                                       APFloat::rmTowardZero);
           Tmp2 = DAG.getConstantFP(apf, VT);
           Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(),
                             Node->getOperand(0), Tmp2, ISD::SETLT);

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=42210&r1=42209&r2=42210&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri Sep 21 17:09:37 2007
@@ -1595,8 +1595,10 @@
     case ISD::SINT_TO_FP: {
       const uint64_t zero[] = {0, 0};
       APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero));
-      (void)apf.convertFromInteger(&Val, 1, Opcode==ISD::SINT_TO_FP,
-                                  APFloat::rmTowardZero);
+      (void)apf.convertFromInteger(&Val, 
+                               MVT::getSizeInBits(Operand.getValueType()), 
+                               Opcode==ISD::SINT_TO_FP,
+                               APFloat::rmTowardZero);
       return getConstantFP(apf, VT);
     }
     case ISD::BIT_CONVERT:

Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=42210&r1=42209&r2=42210&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Fri Sep 21 17:09:37 2007
@@ -393,10 +393,11 @@
         GV.FloatVal = float(GV.IntVal.roundToDouble());
       else if (CE->getType() == Type::DoubleTy)
         GV.DoubleVal = GV.IntVal.roundToDouble();
-       else if (CE->getType() == Type::X86_FP80Ty) {
+      else if (CE->getType() == Type::X86_FP80Ty) {
         const uint64_t zero[] = {0, 0};
         APFloat apf = APFloat(APInt(80, 2, zero));
-        (void)apf.convertFromInteger(GV.IntVal.getRawData(), 2, false, 
+        (void)apf.convertFromInteger(GV.IntVal.getRawData(), 
+                               GV.IntVal.getBitWidth(), false,
                                APFloat::rmTowardZero);
         GV.IntVal = apf.convertToAPInt();
       }
@@ -411,7 +412,8 @@
       else if (CE->getType() == Type::X86_FP80Ty) {
         const uint64_t zero[] = { 0, 0};
         APFloat apf = APFloat(APInt(80, 2, zero));
-        (void)apf.convertFromInteger(GV.IntVal.getRawData(), 2, true,
+        (void)apf.convertFromInteger(GV.IntVal.getRawData(), 
+                               GV.IntVal.getBitWidth(), true,
                                APFloat::rmTowardZero);
         GV.IntVal = apf.convertToAPInt();
       }

Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=42210&r1=42209&r2=42210&view=diff

==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Fri Sep 21 17:09:37 2007
@@ -1180,7 +1180,8 @@
   if (fs==opInvalidOp)
     return fs;
 
-  fs = V.convertFromInteger(x, parts, true, rmNearestTiesToEven);
+  fs = V.convertFromInteger(x, parts * integerPartWidth, true, 
+                            rmNearestTiesToEven);
   assert(fs==opOK);   // should always work
 
   fs = V.multiply(rhs, rounding_mode);
@@ -1459,28 +1460,30 @@
 }
 
 APFloat::opStatus
-APFloat::convertFromInteger(const integerPart *parts,
-			    unsigned int partCount, bool isSigned,
-			    roundingMode rounding_mode)
+APFloat::convertFromInteger(const integerPart *parts, unsigned int width, 
+			    bool isSigned, roundingMode rounding_mode)
 {
-  unsigned int width;
+  unsigned int partCount = partCountForBits(width);
   opStatus status;
-  integerPart *copy;
-
-  copy = new integerPart[partCount];
-  APInt::tcAssign(copy, parts, partCount);
-
-  width = partCount * integerPartWidth;
+  APInt api = APInt(width, partCount, parts);
+  integerPart *copy = new integerPart[partCount];
 
   sign = false;
-  if(isSigned && APInt::tcExtractBit(parts, width - 1)) {
-    sign = true;
-    APInt::tcNegate(copy, partCount);
+  if(isSigned) {
+    if (APInt::tcExtractBit(parts, width - 1)) {
+      sign = true;
+      if (width < partCount * integerPartWidth)
+        api = api.sext(partCount * integerPartWidth);
+    }
+    else if (width < partCount * integerPartWidth)
+      api = api.zext(partCount * integerPartWidth);
+  } else {
+    if (width < partCount * integerPartWidth)
+      api = api.zext(partCount * integerPartWidth);
   }
 
+  APInt::tcAssign(copy, api.getRawData(), partCount);
   status = convertFromUnsignedInteger(copy, partCount, rounding_mode);
-  delete [] copy;
-
   return status;
 }
 

Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=42210&r1=42209&r2=42210&view=diff

==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Fri Sep 21 17:09:37 2007
@@ -58,7 +58,7 @@
   clearUnusedBits();
 }
 
-APInt::APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[])
+APInt::APInt(uint32_t numBits, uint32_t numWords, const uint64_t bigVal[])
   : BitWidth(numBits), VAL(0)  {
   assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
   assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");





More information about the llvm-commits mailing list