convertFromInteger, as originally written, expected sign-extended
authorNeil Booth <neil@daikokuya.co.uk>
Sun, 7 Oct 2007 11:45:55 +0000 (11:45 +0000)
committerNeil Booth <neil@daikokuya.co.uk>
Sun, 7 Oct 2007 11:45:55 +0000 (11:45 +0000)
input.  APInt unfortunately zero-extends signed integers, so Dale
modified the function to expect zero-extended input.  Make this
assumption explicit in the function name.

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

include/llvm/ADT/APFloat.h
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/ExecutionEngine/ExecutionEngine.cpp
lib/Support/APFloat.cpp
lib/VMCore/ConstantFold.cpp

index d62b5c20c6548920eb761ad1a71e5d37419445fd..7505269c68c8b023130a87541a8cdcb6dadfcec5 100644 (file)
@@ -194,8 +194,8 @@ namespace llvm {
     opStatus convert(const fltSemantics &, roundingMode);
     opStatus convertToInteger(integerPart *, unsigned int, bool,
                              roundingMode) const;
-    opStatus convertFromInteger(const integerPart *, unsigned int, bool,
-                               roundingMode);
+    opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int,
+                                            bool, roundingMode);
     opStatus convertFromString(const char *, roundingMode);
     APInt convertToAPInt() const;
     double convertToDouble() const;
index a928968ef90cb28b4d6ed098634b08ec79e86e62..09f45d2ce7e6ee68a927bc06b6319511bc6fee43 100644 (file)
@@ -3234,8 +3234,8 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
           const uint64_t zero[] = {0, 0};
           APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero));
           uint64_t x = 1ULL << ShiftAmt;
-          (void)apf.convertFromInteger(&x, MVT::getSizeInBits(NVT), false, 
-                                       APFloat::rmNearestTiesToEven);
+          (void)apf.convertFromZeroExtendedInteger
+            (&x, MVT::getSizeInBits(NVT), false, APFloat::rmNearestTiesToEven);
           Tmp2 = DAG.getConstantFP(apf, VT);
           Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(),
                             Node->getOperand(0), Tmp2, ISD::SETLT);
index 1e76435b07bbf85d2687bb2db9209ec821fa2709..6a9b14907a05175434f6e06cd1c18317c5a25bea 100644 (file)
@@ -1595,7 +1595,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     case ISD::SINT_TO_FP: {
       const uint64_t zero[] = {0, 0};
       APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero));
-      (void)apf.convertFromInteger(&Val, 
+      (void)apf.convertFromZeroExtendedInteger(&Val, 
                                MVT::getSizeInBits(Operand.getValueType()), 
                                Opcode==ISD::SINT_TO_FP,
                                APFloat::rmNearestTiesToEven);
index 61be35097b9a995e6974b7dfdba59c8c016aeb2b..96604f10bcccdefc675a39de000f4eff157f72e1 100644 (file)
@@ -396,7 +396,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
       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(), 
+        (void)apf.convertFromZeroExtendedInteger(GV.IntVal.getRawData(), 
                                GV.IntVal.getBitWidth(), false,
                                APFloat::rmNearestTiesToEven);
         GV.IntVal = apf.convertToAPInt();
@@ -412,7 +412,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
       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(), 
+        (void)apf.convertFromZeroExtendedInteger(GV.IntVal.getRawData(), 
                                GV.IntVal.getBitWidth(), true,
                                APFloat::rmNearestTiesToEven);
         GV.IntVal = apf.convertToAPInt();
index 2037210e05ba91ee4e97d5189614ac2214437433..5e3504b19a5f9c1751955fc68e8616949989fde9 100644 (file)
@@ -1247,8 +1247,8 @@ APFloat::mod(const APFloat &rhs, roundingMode rounding_mode)
   if (fs==opInvalidOp)
     return fs;
 
-  fs = V.convertFromInteger(x, parts * integerPartWidth, true,
-                            rmNearestTiesToEven);
+  fs = V.convertFromZeroExtendedInteger(x, parts * integerPartWidth, true,
+                                        rmNearestTiesToEven);
   assert(fs==opOK);   // should always work
 
   fs = V.multiply(rhs, rounding_mode);
@@ -1576,9 +1576,11 @@ APFloat::convertFromUnsignedInteger(integerPart *parts,
   return normalize(rounding_mode, lost_fraction);
 }
 
+/* FIXME: should this just take a const APInt reference?  */
 APFloat::opStatus
-APFloat::convertFromInteger(const integerPart *parts, unsigned int width,
-                            bool isSigned, roundingMode rounding_mode)
+APFloat::convertFromZeroExtendedInteger(const integerPart *parts,
+                                        unsigned int width, bool isSigned,
+                                        roundingMode rounding_mode)
 {
   unsigned int partCount = partCountForBits(width);
   opStatus status;
index 72077db378077fc577d3a3bac088a290dd8e82a6..8234900032cf51917f767bdff286ca2ef384b043 100644 (file)
@@ -216,7 +216,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
       uint32_t BitWidth = cast<IntegerType>(SrcTy)->getBitWidth();
       APFloat apf = APFloat(APInt(DestTy->getPrimitiveSizeInBits(),
                                   2, zero));
-      (void)apf.convertFromInteger(api.getRawData(), BitWidth, 
+      (void)apf.convertFromZeroExtendedInteger(api.getRawData(), BitWidth, 
                                    opc==Instruction::SIToFP,
                                    APFloat::rmNearestTiesToEven);
       return ConstantFP::get(DestTy, apf);