From 5bd6eca991a9b72e762c5bd7570c82e59bde0506 Mon Sep 17 00:00:00 2001 From: higher-performance Date: Wed, 9 Jul 2025 15:04:28 -0400 Subject: [PATCH] Improve hash for DenseMapInfo::getHashValue() --- llvm/include/llvm/ADT/DenseMapInfo.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h index 07c37e353a40b..8eb74a7793e26 100644 --- a/llvm/include/llvm/ADT/DenseMapInfo.h +++ b/llvm/include/llvm/ADT/DenseMapInfo.h @@ -82,8 +82,11 @@ struct DenseMapInfo { } static unsigned getHashValue(const T *PtrVal) { - return (unsigned((uintptr_t)PtrVal) >> 4) ^ - (unsigned((uintptr_t)PtrVal) >> 9); + uintptr_t Val = (uintptr_t)PtrVal; + uint32_t Rot = static_cast(Val); + Rot = (Rot >> 9) | (Rot << (32 - 9)); + Val += Rot; + return densemap::detail::mix(Val); } static bool isEqual(const T *LHS, const T *RHS) { return LHS == RHS; }