diff options
author | Dale Johannesen <dalej@apple.com> | 2007-09-14 22:26:36 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2007-09-14 22:26:36 +0000 |
commit | 9e3d3abd937c9bb79d56d25ec0e0724c7cbba67c (patch) | |
tree | c30fb34d6aa099b2c600d4a43088b7e99ef4e79b /lib/VMCore/Constants.cpp | |
parent | 24f2ea3971065eb9e88d50ebeddad0463337cae3 (diff) |
Remove the assumption that FP's are either float or
double from some of the many places in the optimizers
it appears, and do something reasonable with x86
long double.
Make APInt::dump() public, remove newline, use it to
dump ConstantSDNode's.
Allow APFloats in FoldingSet.
Expand X86 backend handling of long doubles (conversions
to/from int, mostly).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41967 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r-- | lib/VMCore/Constants.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index c546045454..2bcd7b68b7 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -103,17 +103,19 @@ bool Constant::ContainsRelocations() const { // Static constructor to create a '0' constant of arbitrary type... Constant *Constant::getNullValue(const Type *Ty) { + static uint64_t zero[2] = {0, 0}; switch (Ty->getTypeID()) { case Type::IntegerTyID: return ConstantInt::get(Ty, 0); case Type::FloatTyID: - return ConstantFP::get(Ty, APFloat(0.0f)); + return ConstantFP::get(Ty, APFloat(APInt(32, 0))); case Type::DoubleTyID: - return ConstantFP::get(Ty, APFloat(0.0)); + return ConstantFP::get(Ty, APFloat(APInt(64, 0))); case Type::X86_FP80TyID: - case Type::PPC_FP128TyID: + return ConstantFP::get(Ty, APFloat(APInt(80, 2, zero))); case Type::FP128TyID: - return ConstantFP::get(Ty, APFloat(0.0)); //FIXME + case Type::PPC_FP128TyID: + return ConstantFP::get(Ty, APFloat(APInt(128, 2, zero))); case Type::PointerTyID: return ConstantPointerNull::get(cast<PointerType>(Ty)); case Type::StructTyID: @@ -259,6 +261,12 @@ bool ConstantFP::isNullValue() const { return Val.isZero() && !Val.isNegative(); } +ConstantFP *ConstantFP::getNegativeZero(const Type *Ty) { + APFloat apf = cast <ConstantFP>(Constant::getNullValue(Ty))->getValueAPF(); + apf.changeSign(); + return ConstantFP::get(Ty, apf); +} + bool ConstantFP::isExactlyValue(const APFloat& V) const { return Val.bitwiseIsEqual(V); } @@ -1925,15 +1933,12 @@ Constant *ConstantExpr::getZeroValueForNegationExpr(const Type *Ty) { if (const VectorType *PTy = dyn_cast<VectorType>(Ty)) if (PTy->getElementType()->isFloatingPoint()) { std::vector<Constant*> zeros(PTy->getNumElements(), - ConstantFP::get(PTy->getElementType(), - PTy->getElementType()==Type::FloatTy ? - APFloat(-0.0f) : APFloat(0.0))); + ConstantFP::getNegativeZero(PTy->getElementType())); return ConstantVector::get(PTy, zeros); } - if (Ty->isFloatingPoint()) - return ConstantFP::get(Ty, Ty==Type::FloatTy ? APFloat(-0.0f) : - APFloat(-0.0)); + if (Ty->isFloatingPoint()) + return ConstantFP::getNegativeZero(Ty); return Constant::getNullValue(Ty); } |