llvm.org GIT mirror llvm / 83f17f2
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 Dylan Noblesmith 8 years ago
1 changed file(s) with 29 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
5959 public:
6060 /// C'tor
6161 Random(unsigned _seed):Seed(_seed) {}
62 /// Return the next random value.
63 unsigned Rand() {
64 unsigned Val = Seed + 0x000b07a1;
62
63 /// Return a random integer, up to a
64 /// maximum of 2**19 - 1.
65 uint32_t Rand() {
66 uint32_t Val = Seed + 0x000b07a1;
6567 Seed = (Val * 0x3c7c0ac1);
6668 // Only lowest 19 bits are random-ish.
6769 return Seed & 0x7ffff;
6870 }
6971
72 /// Return a random 32 bit integer.
73 uint32_t Rand32() {
74 uint32_t Val = Rand();
75 Val &= 0xffff;
76 return Val | (Rand() << 16);
77 }
78
79 /// Return a random 64 bit integer.
80 uint64_t Rand64() {
81 uint64_t Val = Rand32();
82 return Val | (uint64_t(Rand32()) << 32);
83 }
7084 private:
7185 unsigned Seed;
7286 };
347361 }
348362
349363 if (Ty->isFloatingPointTy()) {
364 // Generate 128 random bits, the size of the (currently)
365 // largest floating-point types.
366 uint64_t RandomBits[2];
367 for (unsigned i = 0; i < 2; ++i)
368 RandomBits[i] = Ran->Rand64();
369
370 APInt RandomInt(Ty->getPrimitiveSizeInBits(), makeArrayRef(RandomBits));
371
372 bool isIEEE = !Ty->isX86_FP80Ty() && !Ty->isPPC_FP128Ty();
373 APFloat RandomFloat(RandomInt, isIEEE);
374
350375 if (Ran->Rand() & 1)
351376 return PT->push_back(ConstantFP::getNullValue(Ty));
352 return PT->push_back(ConstantFP::get(Ty,
353 static_cast(1)/Ran->Rand()));
377 return PT->push_back(ConstantFP::get(Ty->getContext(), RandomFloat));
354378 }
355379
356380 if (Ty->isIntegerTy()) {