Index: llvm.test/lib/Support/APInt.cpp =================================================================== --- llvm.test/lib/Support/APInt.cpp (revision 65963) +++ llvm.test/lib/Support/APInt.cpp (working copy) @@ -623,16 +623,29 @@ unsigned APInt::getBitsNeeded(const char return isNegative + tmp.logBase2() + 1; } +// This 64-bit-to-32-bit hash was copied from +// http://www.concentric.net/~Ttwang/tech/inthash.htm . +static uint32_t hash6432shift(uint64_t key) +{ + key = (~key) + (key << 18); // key = (key << 18) - key - 1; + key = key ^ (key >> 31); + key = key * 21; // key = (key + (key << 2)) + (key << 4); + key = key ^ (key >> 11); + key = key + (key << 6); + key = key ^ (key >> 22); + return (uint32_t) key; +} + uint64_t APInt::getHashValue() const { // Put the bit width into the low order bits. - uint64_t hash = BitWidth; + uint64_t hash; // = BitWidth; // Add the sum of the words to the hash. if (isSingleWord()) - hash += VAL << 6; // clear separation of up to 64 bits + hash = hash6432shift(VAL); else - for (unsigned i = 0; i < getNumWords(); ++i) - hash += pVal[i] << 6; // clear sepration of up to 64 bits + for (unsigned i = 0, hash = 0; i < getNumWords(); ++i) + hash ^= hash6432shift(pVal[i]); return hash; }