[llvm] [DenseMap] Update combineHashValue (PR #95970)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 23:46:55 PDT 2024


https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/95970

>From 2ede7c10f0fce95cfaf5980133a3226b6a56814d Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Tue, 18 Jun 2024 11:49:20 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 llvm/include/llvm/ADT/DenseMapInfo.h | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index 5b7dce7b53c62..ba05309e4e413 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -26,17 +26,15 @@ namespace llvm {
 namespace detail {
 
 /// Simplistic combination of 32-bit hash values into 32-bit hash values.
+/// This uses a Murmur3-type mixer "Moremur" from Pelle Evensen.
 static inline unsigned combineHashValue(unsigned a, unsigned b) {
-  uint64_t key = (uint64_t)a << 32 | (uint64_t)b;
-  key += ~(key << 32);
-  key ^= (key >> 22);
-  key += ~(key << 13);
-  key ^= (key >> 8);
-  key += (key << 3);
-  key ^= (key >> 15);
-  key += ~(key << 27);
-  key ^= (key >> 31);
-  return (unsigned)key;
+  uint64_t x = (uint64_t)a << 32 | (uint64_t)b;
+  x ^= x >> 27;
+  x *= 0x3C79AC492BA7B653UL;
+  x ^= x >> 33;
+  x *= 0x1C69B3F74AC4AE35UL;
+  x ^= x >> 27;
+  return (unsigned)x;
 }
 
 } // end namespace detail

>From ac95ae7e0839a2b68be240db2a8e6c4b8224caa8 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Tue, 18 Jun 2024 23:46:47 -0700
Subject: [PATCH 2/2] simpler mixer

Created using spr 1.3.5-bogner
---
 llvm/include/llvm/ADT/DenseMapInfo.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index ba05309e4e413..549d9f3c10e71 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -26,14 +26,11 @@ namespace llvm {
 namespace detail {
 
 /// Simplistic combination of 32-bit hash values into 32-bit hash values.
-/// This uses a Murmur3-type mixer "Moremur" from Pelle Evensen.
+/// This uses a mx-style hash using a constant from splitmix64.
 static inline unsigned combineHashValue(unsigned a, unsigned b) {
   uint64_t x = (uint64_t)a << 32 | (uint64_t)b;
-  x ^= x >> 27;
-  x *= 0x3C79AC492BA7B653UL;
-  x ^= x >> 33;
-  x *= 0x1C69B3F74AC4AE35UL;
-  x ^= x >> 27;
+  x *= 0xbf58476d1ce4e5b9u;
+  x ^= x >> 31;
   return (unsigned)x;
 }
 



More information about the llvm-commits mailing list