[llvm] cf5e2b6 - [KeyInstr] MDNodeKeyImpl<DILocation> skip zero values for hash (#143357)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 9 06:50:36 PDT 2025


Author: Orlando Cazalet-Hyams
Date: 2025-06-09T14:50:33+01:00
New Revision: cf5e2b613d026faa6bd297f3180a76e03d3a8537

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

LOG: [KeyInstr] MDNodeKeyImpl<DILocation> skip zero values for hash (#143357)

[KeyInstr] MDNodeKeyImpl<DILocation> skip zero values for hash

Hashing AtomGroup and AtomRank substantially impacts performance whether Key
Instructions is enabled or not. We can't detect whether it's enabled here
cheaply; avoiding hashing zero values is a good approximation. This affects
Key Instruction builds too, but any potential costs incurred by messing with
the hash distribution (hash_combine(x) != hash_combine(x, 0)) appear to still
be massively outweighed by the overall compile time savings by performing this
check.

See PR for compile-time-tracker numbers.

Added: 
    

Modified: 
    llvm/lib/IR/LLVMContextImpl.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 21f5c06ea24f3..7b6083a7a3496 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -355,13 +355,19 @@ template <> struct MDNodeKeyImpl<DILocation> {
   }
 
   unsigned getHashValue() const {
-    return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode
 #ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
-                        ,
-                        AtomGroup, (uint8_t)AtomRank);
-#else
-    );
+    // Hashing AtomGroup and AtomRank substantially impacts performance whether
+    // Key Instructions is enabled or not. We can't detect whether it's enabled
+    // here cheaply; avoiding hashing zero values is a good approximation. This
+    // affects Key Instruction builds too, but any potential costs incurred by
+    // messing with the hash distribution* appear to still be massively
+    // outweighed by the overall compile time savings by performing this check.
+    // * (hash_combine(x) != hash_combine(x, 0))
+    if (AtomGroup || AtomRank)
+      return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode,
+                          AtomGroup, (uint8_t)AtomRank);
 #endif
+    return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode);
   }
 };
 


        


More information about the llvm-commits mailing list