[llvm] 833d241 - [DenseMap] Canonicalize pointer hashes. NFC (#202226)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 7 12:59:42 PDT 2026


Author: Fangrui Song
Date: 2026-06-07T12:59:37-07:00
New Revision: 833d2418ffe9647b8a88f774208ec20c68805f73

URL: https://github.com/llvm/llvm-project/commit/833d2418ffe9647b8a88f774208ec20c68805f73
DIFF: https://github.com/llvm/llvm-project/commit/833d2418ffe9647b8a88f774208ec20c68805f73.diff

LOG: [DenseMap] Canonicalize pointer hashes. NFC (#202226)

`(p>>4)^(p>>9)` does not mix the high bits of the address. Pointers from
one allocator grown across multiple slabs whose low-bit windows overlap
map to the same narrow bucket range, an issue fixed by #197390.

Fix by delegating to the canonical pointer hash.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/ImmutableList.h
    llvm/include/llvm/CodeGen/SelectionDAGNodes.h
    llvm/include/llvm/IR/Attributes.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/ImmutableList.h b/llvm/include/llvm/ADT/ImmutableList.h
index 7694f571a8283..bbf0a96464e58 100644
--- a/llvm/include/llvm/ADT/ImmutableList.h
+++ b/llvm/include/llvm/ADT/ImmutableList.h
@@ -221,9 +221,7 @@ class ImmutableListFactory {
 
 template <typename T> struct DenseMapInfo<ImmutableList<T>, void> {
   static unsigned getHashValue(ImmutableList<T> X) {
-    uintptr_t PtrVal = reinterpret_cast<uintptr_t>(X.getInternalPointer());
-    return (unsigned((uintptr_t)PtrVal) >> 4) ^
-           (unsigned((uintptr_t)PtrVal) >> 9);
+    return DenseMapInfo<const void *>::getHashValue(X.getInternalPointer());
   }
 
   static bool isEqual(ImmutableList<T> X1, ImmutableList<T> X2) {

diff  --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index 8089b638ea2bc..6292dcd97fc8d 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -240,8 +240,8 @@ class SDValue {
 
 template <> struct DenseMapInfo<SDValue> {
   static unsigned getHashValue(const SDValue &Val) {
-    return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
-            (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
+    return DenseMapInfo<const void *>::getHashValue(Val.getNode()) +
+           Val.getResNo();
   }
 
   static bool isEqual(const SDValue &LHS, const SDValue &RHS) {

diff  --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index 5dc09ef66370a..6250dde919341 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -527,8 +527,7 @@ class AttributeSet {
 /// Provide DenseMapInfo for AttributeSet.
 template <> struct DenseMapInfo<AttributeSet, void> {
   static unsigned getHashValue(AttributeSet AS) {
-    return (unsigned((uintptr_t)AS.SetNode) >> 4) ^
-           (unsigned((uintptr_t)AS.SetNode) >> 9);
+    return DenseMapInfo<const void *>::getHashValue(AS.SetNode);
   }
 
   static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; }
@@ -1090,8 +1089,7 @@ class AttributeList {
 /// Provide DenseMapInfo for AttributeList.
 template <> struct DenseMapInfo<AttributeList, void> {
   static unsigned getHashValue(AttributeList AS) {
-    return (unsigned((uintptr_t)AS.pImpl) >> 4) ^
-           (unsigned((uintptr_t)AS.pImpl) >> 9);
+    return DenseMapInfo<const void *>::getHashValue(AS.pImpl);
   }
 
   static bool isEqual(AttributeList LHS, AttributeList RHS) {


        


More information about the llvm-commits mailing list