Next round of APFloat changes.
Use APFloat in UpgradeParser and AsmParser.
Change all references to ConstantFP to use the
APFloat interface rather than double. Remove
the ConstantFP double interfaces.
Use APFloat functions for constant folding arithmetic
and comparisons.
(There are still way too many places APFloat is
just a wrapper around host float/double, but we're
getting there.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41747 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index fa6f569..e80afd4 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -829,8 +829,8 @@
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
// FP Constants are printed as integer constants to avoid losing
// precision...
- double Val = CFP->getValue();
if (CFP->getType() == Type::DoubleTy) {
+ double Val = CFP->getValueAPF().convertToDouble();
if (TAI->getData64bitsDirective())
O << TAI->getData64bitsDirective() << DoubleToBits(Val) << "\t"
<< TAI->getCommentString() << " double value: " << Val << "\n";
@@ -851,6 +851,7 @@
}
return;
} else {
+ float Val = CFP->getValueAPF().convertToFloat();
O << TAI->getData32bitsDirective() << FloatToBits(Val)
<< "\t" << TAI->getCommentString() << " float " << Val << "\n";
return;
diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp
index 36060e1..af2555d 100644
--- a/lib/CodeGen/MachOWriter.cpp
+++ b/lib/CodeGen/MachOWriter.cpp
@@ -861,7 +861,8 @@
break;
}
case Type::FloatTyID: {
- uint64_t val = FloatToBits(cast<ConstantFP>(PC)->getValue());
+ uint64_t val = FloatToBits(cast<ConstantFP>(PC)->
+ getValueAPF().convertToFloat());
if (TD->isBigEndian())
val = ByteSwap_32(val);
ptr[0] = val;
@@ -871,7 +872,8 @@
break;
}
case Type::DoubleTyID: {
- uint64_t val = DoubleToBits(cast<ConstantFP>(PC)->getValue());
+ uint64_t val = DoubleToBits(cast<ConstantFP>(PC)->
+ getValueAPF().convertToDouble());
if (TD->isBigEndian())
val = ByteSwap_64(val);
ptr[0] = val;
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index a695048..d1e9365 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -840,7 +840,7 @@
return N = DAG.getNode(ISD::BUILD_VECTOR, VT,
&Ops[0], Ops.size());
} else if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
- return N = DAG.getConstantFP(CFP->getValue(), VT);
+ return N = DAG.getConstantFP(CFP->getValueAPF(), VT);
} else if (const VectorType *PTy = dyn_cast<VectorType>(VTy)) {
unsigned NumElements = PTy->getNumElements();
MVT::ValueType PVT = TLI.getValueType(PTy->getElementType());
@@ -2003,7 +2003,8 @@
const Type *ElTy = DestTy->getElementType();
if (ElTy->isFloatingPoint()) {
unsigned VL = DestTy->getNumElements();
- std::vector<Constant*> NZ(VL, ConstantFP::get(ElTy, -0.0));
+ std::vector<Constant*> NZ(VL, ConstantFP::get(ElTy,
+ ElTy==Type::FloatTy ? APFloat(-0.0f) : APFloat(-0.0)));
Constant *CNZ = ConstantVector::get(&NZ[0], NZ.size());
if (CV == CNZ) {
SDOperand Op2 = getValue(I.getOperand(1));