mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
llvm-stress: stop abusing ConstantFP::get()
ConstantFP::get(Type*, double) is unreliably host-specific: it can't handle a type like PPC128 on an x86 host. It even has a comment to that effect: "This should only be used for simple constant values like 2.0/1.0 etc, that are known-valid both as host double and as the target format." Instead, use APFloat. While we're at it, randomize the floating point value more thoroughly; it was previously limited to the range 0 to 2**19 - 1. PR12451. llvm-svn: 154446
This commit is contained in:
parent
2e2de248b0
commit
1e0746761c
@ -60,14 +60,28 @@ class Random {
|
||||
public:
|
||||
/// C'tor
|
||||
Random(unsigned _seed):Seed(_seed) {}
|
||||
/// Return the next random value.
|
||||
unsigned Rand() {
|
||||
unsigned Val = Seed + 0x000b07a1;
|
||||
|
||||
/// Return a random integer, up to a
|
||||
/// maximum of 2**19 - 1.
|
||||
uint32_t Rand() {
|
||||
uint32_t Val = Seed + 0x000b07a1;
|
||||
Seed = (Val * 0x3c7c0ac1);
|
||||
// Only lowest 19 bits are random-ish.
|
||||
return Seed & 0x7ffff;
|
||||
}
|
||||
|
||||
/// Return a random 32 bit integer.
|
||||
uint32_t Rand32() {
|
||||
uint32_t Val = Rand();
|
||||
Val &= 0xffff;
|
||||
return Val | (Rand() << 16);
|
||||
}
|
||||
|
||||
/// Return a random 64 bit integer.
|
||||
uint64_t Rand64() {
|
||||
uint64_t Val = Rand32();
|
||||
return Val | (uint64_t(Rand32()) << 32);
|
||||
}
|
||||
private:
|
||||
unsigned Seed;
|
||||
};
|
||||
@ -348,10 +362,20 @@ struct ConstModifier: public Modifier {
|
||||
}
|
||||
|
||||
if (Ty->isFloatingPointTy()) {
|
||||
// Generate 128 random bits, the size of the (currently)
|
||||
// largest floating-point types.
|
||||
uint64_t RandomBits[2];
|
||||
for (unsigned i = 0; i < 2; ++i)
|
||||
RandomBits[i] = Ran->Rand64();
|
||||
|
||||
APInt RandomInt(Ty->getPrimitiveSizeInBits(), makeArrayRef(RandomBits));
|
||||
|
||||
bool isIEEE = !Ty->isX86_FP80Ty() && !Ty->isPPC_FP128Ty();
|
||||
APFloat RandomFloat(RandomInt, isIEEE);
|
||||
|
||||
if (Ran->Rand() & 1)
|
||||
return PT->push_back(ConstantFP::getNullValue(Ty));
|
||||
return PT->push_back(ConstantFP::get(Ty,
|
||||
static_cast<double>(1)/Ran->Rand()));
|
||||
return PT->push_back(ConstantFP::get(Ty->getContext(), RandomFloat));
|
||||
}
|
||||
|
||||
if (Ty->isIntegerTy()) {
|
||||
|
Loading…
Reference in New Issue
Block a user