diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 20:44:23 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 20:44:23 +0000 |
commit | 0d54b7df4f99fb18c3893455ad3864326f74feb6 (patch) | |
tree | c47e851a0339e707ad52ad6064e618d992ab0c67 /lib | |
parent | 53ee4f9d4083ce5106d95ab23985570a1f7413e5 (diff) | |
download | external_llvm-0d54b7df4f99fb18c3893455ad3864326f74feb6.zip external_llvm-0d54b7df4f99fb18c3893455ad3864326f74feb6.tar.gz external_llvm-0d54b7df4f99fb18c3893455ad3864326f74feb6.tar.bz2 |
Use the APInt versions of the bit-wise conversions of float/double to int
and back. While this is not strictly necessary, it does pave the way for
future changes in casting. It should now be possible to improve vector
casting to deal with un-equal fp/int sizes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34808 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 2e78bc9..97f760f 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -66,16 +66,16 @@ static Constant *CastConstantVector(ConstantVector *CV, assert(DstEltTy->isFloatingPoint()); if (DstEltTy->getTypeID() == Type::DoubleTyID) { for (unsigned i = 0; i != SrcNumElts; ++i) { - double V = - BitsToDouble(cast<ConstantInt>(CV->getOperand(i))->getZExtValue()); + ConstantInt *CI = cast<ConstantInt>(CV->getOperand(i)); + double V = CI->getValue().bitsToDouble(); Result.push_back(ConstantFP::get(Type::DoubleTy, V)); } return ConstantVector::get(Result); } assert(DstEltTy == Type::FloatTy && "Unknown fp type!"); for (unsigned i = 0; i != SrcNumElts; ++i) { - float V = - BitsToFloat(cast<ConstantInt>(CV->getOperand(i))->getZExtValue()); + ConstantInt *CI = cast<ConstantInt>(CV->getOperand(i)); + float V = CI->getValue().bitsToFloat(); Result.push_back(ConstantFP::get(Type::FloatTy, V)); } return ConstantVector::get(Result); @@ -304,9 +304,9 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, if (DestTy->isFloatingPoint()) { if (DestTy == Type::FloatTy) - return ConstantFP::get(DestTy, BitsToFloat(CI->getZExtValue())); + return ConstantFP::get(DestTy, CI->getValue().bitsToFloat()); assert(DestTy == Type::DoubleTy && "Unknown FP type!"); - return ConstantFP::get(DestTy, BitsToDouble(CI->getZExtValue())); + return ConstantFP::get(DestTy, CI->getValue().bitsToDouble()); } // Otherwise, can't fold this (packed?) return 0; @@ -316,10 +316,12 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, if (const ConstantFP *FP = dyn_cast<ConstantFP>(V)) { // FP -> Integral. if (DestTy == Type::Int32Ty) { - return ConstantInt::get(DestTy, FloatToBits(FP->getValue())); + APInt Val(32, 0); + return ConstantInt::get(Val.floatToBits(FP->getValue())); } else { assert(DestTy == Type::Int64Ty && "only support f32/f64 for now!"); - return ConstantInt::get(DestTy, DoubleToBits(FP->getValue())); + APInt Val(64, 0); + return ConstantInt::get(Val.doubleToBits(FP->getValue())); } } return 0; |