diff options
author | Dylan Noblesmith <nobled@dreamwidth.org> | 2012-04-10 22:44:51 +0000 |
---|---|---|
committer | Dylan Noblesmith <nobled@dreamwidth.org> | 2012-04-10 22:44:51 +0000 |
commit | 83f17f25fc560db4f756010a1bbe1f8eb1d74b12 (patch) | |
tree | 5ea2628f003f8f27a146d172af796a906d638005 /tools/llvm-stress | |
parent | 701de8fafc8db86a0a7df61b177720b1f681c60c (diff) | |
download | external_llvm-83f17f25fc560db4f756010a1bbe1f8eb1d74b12.zip external_llvm-83f17f25fc560db4f756010a1bbe1f8eb1d74b12.tar.gz external_llvm-83f17f25fc560db4f756010a1bbe1f8eb1d74b12.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154446 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-stress')
-rw-r--r-- | tools/llvm-stress/llvm-stress.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp index 7da80bc..d284ea5 100644 --- a/tools/llvm-stress/llvm-stress.cpp +++ b/tools/llvm-stress/llvm-stress.cpp @@ -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()) { |