diff options
author | Dale Johannesen <dalej@apple.com> | 2008-10-09 23:00:39 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2008-10-09 23:00:39 +0000 |
commit | 23a98551ab65eeb8fe5019df8b7db4891582a4bd (patch) | |
tree | 90d6731fd446c04df49383b8a23da0461337ba09 /lib/VMCore | |
parent | 7111b02c734c992b8c97d9918118768026dad79e (diff) | |
download | external_llvm-23a98551ab65eeb8fe5019df8b7db4891582a4bd.zip external_llvm-23a98551ab65eeb8fe5019df8b7db4891582a4bd.tar.gz external_llvm-23a98551ab65eeb8fe5019df8b7db4891582a4bd.tar.bz2 |
Add a "loses information" return value to APFloat::convert
and APFloat::convertToInteger. Restore return value to
IEEE754. Adjust all users accordingly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57329 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 26 | ||||
-rw-r--r-- | lib/VMCore/Core.cpp | 4 |
3 files changed, 23 insertions, 13 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 9256109..93ee7fe 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -213,13 +213,14 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, case Instruction::FPTrunc: case Instruction::FPExt: if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V)) { + bool ignored; APFloat Val = FPC->getValueAPF(); Val.convert(DestTy == Type::FloatTy ? APFloat::IEEEsingle : DestTy == Type::DoubleTy ? APFloat::IEEEdouble : DestTy == Type::X86_FP80Ty ? APFloat::x87DoubleExtended : DestTy == Type::FP128Ty ? APFloat::IEEEquad : APFloat::Bogus, - APFloat::rmNearestTiesToEven); + APFloat::rmNearestTiesToEven, &ignored); return ConstantFP::get(Val); } return 0; // Can't fold. @@ -227,10 +228,11 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, case Instruction::FPToSI: if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V)) { const APFloat &V = FPC->getValueAPF(); + bool ignored; uint64_t x[2]; uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth(); (void) V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI, - APFloat::rmTowardZero); + APFloat::rmTowardZero, &ignored); APInt Val(DestBitWidth, 2, x); return ConstantInt::get(Val); } diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 4471cfd..b0dd163 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -373,7 +373,8 @@ ConstantFP *ConstantFP::get(const APFloat &V) { /// 2.0/1.0 etc, that are known-valid both as double and as the target format. ConstantFP *ConstantFP::get(const Type *Ty, double V) { APFloat FV(V); - FV.convert(*TypeToFloatSemantics(Ty), APFloat::rmNearestTiesToEven); + bool ignored; + FV.convert(*TypeToFloatSemantics(Ty), APFloat::rmNearestTiesToEven, &ignored); return get(FV); } @@ -955,20 +956,25 @@ bool ConstantInt::isValueValidForType(const Type *Ty, int64_t Val) { bool ConstantFP::isValueValidForType(const Type *Ty, const APFloat& Val) { // convert modifies in place, so make a copy. APFloat Val2 = APFloat(Val); + bool losesInfo; switch (Ty->getTypeID()) { default: return false; // These can't be represented as floating point! // FIXME rounding mode needs to be more flexible - case Type::FloatTyID: - return &Val2.getSemantics() == &APFloat::IEEEsingle || - Val2.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven) == - APFloat::opOK; - case Type::DoubleTyID: - return &Val2.getSemantics() == &APFloat::IEEEsingle || - &Val2.getSemantics() == &APFloat::IEEEdouble || - Val2.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven) == - APFloat::opOK; + case Type::FloatTyID: { + if (&Val2.getSemantics() == &APFloat::IEEEsingle) + return true; + Val2.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &losesInfo); + return !losesInfo; + } + case Type::DoubleTyID: { + if (&Val2.getSemantics() == &APFloat::IEEEsingle || + &Val2.getSemantics() == &APFloat::IEEEdouble) + return true; + Val2.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &losesInfo); + return !losesInfo; + } case Type::X86_FP80TyID: return &Val2.getSemantics() == &APFloat::IEEEsingle || &Val2.getSemantics() == &APFloat::IEEEdouble || diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index a802373..afc1c90 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -302,7 +302,9 @@ static const fltSemantics &SemanticsForType(Type *Ty) { LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) { APFloat APN(N); - APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven); + bool ignored; + APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven, + &ignored); return wrap(ConstantFP::get(APN)); } |