diff options
author | Dale Johannesen <dalej@apple.com> | 2007-09-30 18:19:03 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2007-09-30 18:19:03 +0000 |
commit | 88216af3ea4bb1c68a8793ed1d3b30308b64ab0e (patch) | |
tree | db3b24ea0faceec5eb021615d89bf25953be1076 /lib/VMCore/ConstantFold.cpp | |
parent | cce23a4c3585d9d7df538bbc71151624a18f40cd (diff) | |
download | external_llvm-88216af3ea4bb1c68a8793ed1d3b30308b64ab0e.zip external_llvm-88216af3ea4bb1c68a8793ed1d3b30308b64ab0e.tar.gz external_llvm-88216af3ea4bb1c68a8793ed1d3b30308b64ab0e.tar.bz2 |
Constant fold int-to-long-double conversions;
use APFloat for int-to-float/double; use
round-to-nearest for these (implementation-defined,
seems to match gcc).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42484 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 73ca47a..72077db 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -209,25 +209,17 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, return ConstantInt::get(DestTy, 0); return 0; // Other pointer types cannot be casted case Instruction::UIToFP: - if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) { - double d = CI->getValue().roundToDouble(); - if (DestTy==Type::FloatTy) - return ConstantFP::get(DestTy, APFloat((float)d)); - else if (DestTy==Type::DoubleTy) - return ConstantFP::get(DestTy, APFloat(d)); - else - return 0; // FIXME do this for long double - } - return 0; case Instruction::SIToFP: if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) { - double d = CI->getValue().signedRoundToDouble(); - if (DestTy==Type::FloatTy) - return ConstantFP::get(DestTy, APFloat((float)d)); - else if (DestTy==Type::DoubleTy) - return ConstantFP::get(DestTy, APFloat(d)); - else - return 0; // FIXME do this for long double + APInt api = CI->getValue(); + const uint64_t zero[] = {0, 0}; + uint32_t BitWidth = cast<IntegerType>(SrcTy)->getBitWidth(); + APFloat apf = APFloat(APInt(DestTy->getPrimitiveSizeInBits(), + 2, zero)); + (void)apf.convertFromInteger(api.getRawData(), BitWidth, + opc==Instruction::SIToFP, + APFloat::rmNearestTiesToEven); + return ConstantFP::get(DestTy, apf); } return 0; case Instruction::ZExt: |