[llvm] [ADT] Update hash function of uint64_t for DenseMap (PR #95734)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 17 01:07:39 PDT 2024


================
@@ -151,7 +151,7 @@ template<> struct DenseMapInfo<unsigned long long> {
   static inline unsigned long long getTombstoneKey() { return ~0ULL - 1ULL; }
 
   static unsigned getHashValue(const unsigned long long& Val) {
-    return (unsigned)(Val * 37ULL);
+    return DenseMapInfo<unsigned>(Val) ^ DenseMapInfo<unsigned>(Val >> 32);
----------------
nikic wrote:

While I think that DenseMaps hash functions could use some overhaul, I don't think that switching to Hashing.h in this one place would be appropriate. If we want to do that, we should do so for all the DenseMapInfo hashes, after properly analyzing the cost of the more expensive hash vs the benefit of better hash distribution.

We may also have to refactor Hashing.h to reduce the build-time overhead for places that like this that don't need the full infrastructure and its build overhead.

https://github.com/llvm/llvm-project/pull/95734


More information about the llvm-commits mailing list