[llvm-commits] [llvm] r154446 - /llvm/trunk/tools/llvm-stress/llvm-stress.cpp
Dylan Noblesmith
nobled at dreamwidth.org
Tue Apr 10 15:44:51 PDT 2012
Author: nobled
Date: Tue Apr 10 17:44:51 2012
New Revision: 154446
URL: http://llvm.org/viewvc/llvm-project?rev=154446&view=rev
Log:
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.
Modified:
llvm/trunk/tools/llvm-stress/llvm-stress.cpp
Modified: llvm/trunk/tools/llvm-stress/llvm-stress.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-stress/llvm-stress.cpp?rev=154446&r1=154445&r2=154446&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-stress/llvm-stress.cpp (original)
+++ llvm/trunk/tools/llvm-stress/llvm-stress.cpp Tue Apr 10 17:44:51 2012
@@ -60,14 +60,28 @@
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 @@
}
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()) {
More information about the llvm-commits
mailing list