[llvm] [ADT] Use xxh3_64bits in DenseMapInfo<StringRef>::getHashValue (PR #191115)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 10 10:07:48 PDT 2026
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/191115
>From e31a89967a76eac1fa9e57c7df89eab0dc88e5c3 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Wed, 8 Apr 2026 22:49:19 -0700
Subject: [PATCH] [ADT] Use xxh3_64bits in
DenseMapInfo<StringRef>::getHashValue
This function is heavily used in lld/ELF to hash symbol names. When
linking a clang Release+Asserts benchmark, this yields ~1% wall-time
improvement.
In LLVM_ENABLE_ABI_BREAKING_CHECKS builds, the result is XORed with
get_execution_seed() to preserve the non-deterministic seed protection
from Hashing.h.
---
llvm/lib/Support/StringRef.cpp | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp
index 2e8fba8cbfa37..8b303a2be0857 100644
--- a/llvm/lib/Support/StringRef.cpp
+++ b/llvm/lib/Support/StringRef.cpp
@@ -13,6 +13,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/edit_distance.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/xxhash.h"
#include <bitset>
using namespace llvm;
@@ -614,5 +615,12 @@ unsigned DenseMapInfo<StringRef, void>::getHashValue(StringRef Val) {
"Cannot hash the empty key!");
assert(Val.data() != getTombstoneKey().data() &&
"Cannot hash the tombstone key!");
- return (unsigned)(hash_value(Val));
+ auto hash = xxh3_64bits(Val);
+ // In LLVM_ENABLE_ABI_BREAKING_CHECKS builds, the seed is non-deterministic
+ // per process (address of a function in LLVMSupport) to prevent having users
+ // depend on the particular hash values.
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS
+ hash ^= hashing::detail::get_execution_seed();
+#endif
+ return hash;
}
More information about the llvm-commits
mailing list