[llvm] [KeyInstr] MDNodeKeyImpl<DILocation> skip zero values for hash (PR #143357)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 9 02:22:27 PDT 2025
https://github.com/OCHyams created https://github.com/llvm/llvm-project/pull/143357
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.
---
>From compile-time-tracker:
1. this patch
2. set LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS=ON by default (enabling support in LLVM, not enabling the feature)
3. base
```
Commit stage1-O3 stage1-ReleaseThinLTO stage1-ReleaseLTO-g stage1-O0-g stage1-aarch64-O3 stage1-aarch64-O0-g stage2-O3 stage2-O0-g stage2-clang
1. 3fa3a147a0 61213M (+0.01%) 77400M (+0.01%) 89460M (-0.16%) 18896M (-0.42%) 68673M (+0.00%) 23128M (-0.31%) 53427M (+0.05%) 16547M (-1.53%) 34059533M (+0.00%)
2. 882faf0ac5 61209M (+0.01%) 77393M (+0.00%) 89608M (+0.22%) 18975M (+0.53%) 68672M (+0.02%) 23201M (+0.42%) 53398M (-0.05%) 16805M (+1.75%) 34059472M (+0.01%)
3. 54d544b831 61205M 77393M 89410M 18874M 68660M 23104M 53426M 16516M 34055496M
```
Compare 2-1: https://llvm-compile-time-tracker.com/compare.php?from=882faf0ac573476edf0f4026a69f6f86f316c821&to=3fa3a147a0d7a579f92f5ca6db1bfcdd485f8ffa&stat=instructions%3Au
Compare 3-2: https://llvm-compile-time-tracker.com/compare.php?from=54d544b83141dc0b20727673f68793728ed54793&to=882faf0ac573476edf0f4026a69f6f86f316c821&stat=instructions%3Au
>From 85bea6e0f7971b942878a5dec38288a85b26e83c Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 9 Jun 2025 09:24:07 +0100
Subject: [PATCH] [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.
---
llvm/lib/IR/LLVMContextImpl.h | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
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