mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 06:33:24 +00:00
Do not use host floating point types when emitting
ASCII IR; loading and storing these can change the bits of NaNs on some hosts. Remove or add warnings at a few other places using host floating point; this is a bad thing to do in general. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62712 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a095c972cc
commit
541ed9fd02
@ -225,8 +225,6 @@ public:
|
|||||||
void AddInteger(unsigned long I);
|
void AddInteger(unsigned long I);
|
||||||
void AddInteger(long long I);
|
void AddInteger(long long I);
|
||||||
void AddInteger(unsigned long long I);
|
void AddInteger(unsigned long long I);
|
||||||
void AddFloat(float F);
|
|
||||||
void AddDouble(double D);
|
|
||||||
void AddString(const std::string &String);
|
void AddString(const std::string &String);
|
||||||
void AddString(const char* String);
|
void AddString(const char* String);
|
||||||
|
|
||||||
|
@ -361,7 +361,9 @@ inline float BitsToFloat(uint32_t Bits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// DoubleToBits - This function takes a double and returns the bit
|
/// DoubleToBits - This function takes a double and returns the bit
|
||||||
/// equivalent 64-bit integer.
|
/// equivalent 64-bit integer. Note that copying doubles around
|
||||||
|
/// changes the bits of NaNs on some hosts, notably x86, so this
|
||||||
|
/// routine cannot be used if these bits are needed.
|
||||||
inline uint64_t DoubleToBits(double Double) {
|
inline uint64_t DoubleToBits(double Double) {
|
||||||
union {
|
union {
|
||||||
uint64_t L;
|
uint64_t L;
|
||||||
@ -372,7 +374,9 @@ inline uint64_t DoubleToBits(double Double) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// FloatToBits - This function takes a float and returns the bit
|
/// FloatToBits - This function takes a float and returns the bit
|
||||||
/// equivalent 32-bit integer.
|
/// equivalent 32-bit integer. Note that copying floats around
|
||||||
|
/// changes the bits of NaNs on some hosts, notably x86, so this
|
||||||
|
/// routine cannot be used if these bits are needed.
|
||||||
inline uint32_t FloatToBits(float Float) {
|
inline uint32_t FloatToBits(float Float) {
|
||||||
union {
|
union {
|
||||||
uint32_t I;
|
uint32_t I;
|
||||||
|
@ -599,7 +599,8 @@ APFloat::copySignificand(const APFloat &rhs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Make this number a NaN, with an arbitrary but deterministic value
|
/* Make this number a NaN, with an arbitrary but deterministic value
|
||||||
for the significand. */
|
for the significand. If double or longer, this is a signalling NaN,
|
||||||
|
which may not be ideal. */
|
||||||
void
|
void
|
||||||
APFloat::makeNaN(void)
|
APFloat::makeNaN(void)
|
||||||
{
|
{
|
||||||
|
@ -61,12 +61,6 @@ void FoldingSetNodeID::AddInteger(unsigned long long I) {
|
|||||||
if ((uint64_t)(int)I != I)
|
if ((uint64_t)(int)I != I)
|
||||||
Bits.push_back(unsigned(I >> 32));
|
Bits.push_back(unsigned(I >> 32));
|
||||||
}
|
}
|
||||||
void FoldingSetNodeID::AddFloat(float F) {
|
|
||||||
Bits.push_back(FloatToBits(F));
|
|
||||||
}
|
|
||||||
void FoldingSetNodeID::AddDouble(double D) {
|
|
||||||
AddInteger(DoubleToBits(D));
|
|
||||||
}
|
|
||||||
|
|
||||||
void FoldingSetNodeID::AddString(const char *String) {
|
void FoldingSetNodeID::AddString(const char *String) {
|
||||||
unsigned Size = static_cast<unsigned>(strlen(String));
|
unsigned Size = static_cast<unsigned>(strlen(String));
|
||||||
|
@ -640,6 +640,7 @@ static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
|
|||||||
// make sure that we only output it in exponential format if we can parse
|
// make sure that we only output it in exponential format if we can parse
|
||||||
// the value back and get the same value.
|
// the value back and get the same value.
|
||||||
//
|
//
|
||||||
|
bool ignored;
|
||||||
bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
|
bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
|
||||||
double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
|
double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
|
||||||
CFP->getValueAPF().convertToFloat();
|
CFP->getValueAPF().convertToFloat();
|
||||||
@ -659,11 +660,20 @@ static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise we could not reparse it to exactly the same value, so we must
|
// Otherwise we could not reparse it to exactly the same value, so we must
|
||||||
// output the string in hexadecimal format!
|
// output the string in hexadecimal format! Note that loading and storing
|
||||||
|
// floating point types changes the bits of NaNs on some hosts, notably
|
||||||
|
// x86, so we must not use these types.
|
||||||
assert(sizeof(double) == sizeof(uint64_t) &&
|
assert(sizeof(double) == sizeof(uint64_t) &&
|
||||||
"assuming that double is 64 bits!");
|
"assuming that double is 64 bits!");
|
||||||
char Buffer[40];
|
char Buffer[40];
|
||||||
Out << "0x" << utohex_buffer(uint64_t(DoubleToBits(Val)), Buffer+40);
|
APFloat apf = CFP->getValueAPF();
|
||||||
|
// Floats are represented in ASCII IR as double, convert.
|
||||||
|
if (!isDouble)
|
||||||
|
apf.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
|
||||||
|
&ignored);
|
||||||
|
Out << "0x" <<
|
||||||
|
utohex_buffer(uint64_t(apf.bitcastToAPInt().getZExtValue()),
|
||||||
|
Buffer+40);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
; RUN: llvm-as < %s | opt -simplifycfg -instcombine | llvm-dis | grep 0x7FF8000000000000 | count 7
|
; RUN: llvm-as < %s | opt -simplifycfg -instcombine | llvm-dis | grep 0x7FF8000000000000 | count 7
|
||||||
; RUN: llvm-as < %s | opt -simplifycfg -instcombine | llvm-dis | grep 0x7FF80000FFFFFFFF | count 5
|
; RUN: llvm-as < %s | opt -simplifycfg -instcombine | llvm-dis | grep 0x7FF00000FFFFFFFF | count 5
|
||||||
; RUN: llvm-as < %s | opt -simplifycfg -instcombine | llvm-dis | grep {0\\.0} | count 3
|
; RUN: llvm-as < %s | opt -simplifycfg -instcombine | llvm-dis | grep {0\\.0} | count 3
|
||||||
; RUN: llvm-as < %s | opt -simplifycfg -instcombine | llvm-dis | grep {3\\.5} | count 1
|
; RUN: llvm-as < %s | opt -simplifycfg -instcombine | llvm-dis | grep {3\\.5} | count 1
|
||||||
; XFAIL: x86_64
|
;
|
||||||
|
|
||||||
; ModuleID = 'apf.c'
|
; ModuleID = 'apf.c'
|
||||||
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
|
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user