Skip to content

Commit cf5e2b6

Browse files
authored
[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.
1 parent e4060d3 commit cf5e2b6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

llvm/lib/IR/LLVMContextImpl.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,19 @@ template <> struct MDNodeKeyImpl<DILocation> {
355355
}
356356

357357
unsigned getHashValue() const {
358-
return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode
359358
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
360-
,
361-
AtomGroup, (uint8_t)AtomRank);
362-
#else
363-
);
359+
// Hashing AtomGroup and AtomRank substantially impacts performance whether
360+
// Key Instructions is enabled or not. We can't detect whether it's enabled
361+
// here cheaply; avoiding hashing zero values is a good approximation. This
362+
// affects Key Instruction builds too, but any potential costs incurred by
363+
// messing with the hash distribution* appear to still be massively
364+
// outweighed by the overall compile time savings by performing this check.
365+
// * (hash_combine(x) != hash_combine(x, 0))
366+
if (AtomGroup || AtomRank)
367+
return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode,
368+
AtomGroup, (uint8_t)AtomRank);
364369
#endif
370+
return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode);
365371
}
366372
};
367373

0 commit comments

Comments
 (0)