[llvm] r230013 - Constants.cpp: getElementAsAPFloat(): Don't handle constant value via host's float/double, just handle with APInt/APFloat.
NAKAMURA Takumi
geek4civic at gmail.com
Fri Feb 20 06:24:49 PST 2015
Author: chapuni
Date: Fri Feb 20 08:24:49 2015
New Revision: 230013
URL: http://llvm.org/viewvc/llvm-project?rev=230013&view=rev
Log:
Constants.cpp: getElementAsAPFloat(): Don't handle constant value via host's float/double, just handle with APInt/APFloat.
x87 FPU didn't keep SNAN, but demoted to QNAN.
Modified:
llvm/trunk/lib/IR/Constants.cpp
Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=230013&r1=230012&r2=230013&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Fri Feb 20 08:24:49 2015
@@ -2715,18 +2715,15 @@ uint64_t ConstantDataSequential::getElem
/// type, return the specified element as an APFloat.
APFloat ConstantDataSequential::getElementAsAPFloat(unsigned Elt) const {
const char *EltPtr = getElementPointer(Elt);
+ auto EltVal = *reinterpret_cast<const uint64_t *>(EltPtr);
switch (getElementType()->getTypeID()) {
default:
llvm_unreachable("Accessor can only be used when element is float/double!");
- case Type::FloatTyID: {
- const float *FloatPrt = reinterpret_cast<const float *>(EltPtr);
- return APFloat(*const_cast<float *>(FloatPrt));
- }
- case Type::DoubleTyID: {
- const double *DoublePtr = reinterpret_cast<const double *>(EltPtr);
- return APFloat(*const_cast<double *>(DoublePtr));
- }
+ case Type::FloatTyID:
+ return APFloat(APFloat::IEEEsingle, APInt(32, EltVal));
+ case Type::DoubleTyID:
+ return APFloat(APFloat::IEEEdouble, APInt(64, EltVal));
}
}
More information about the llvm-commits
mailing list