-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[DenseMap] Update combineHashValue #95970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DenseMap] Update combineHashValue #95970
Conversation
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-llvm-adt Author: Fangrui Song (MaskRay) Changes
Measured time to compute [0,1000000000) values on an i7-11850H:
Full diff: https://github.com/llvm/llvm-project/pull/95970.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index 5b7dce7b53c62..ba05309e4e413 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -26,17 +26,15 @@ namespace llvm {
namespace detail {
/// Simplistic combination of 32-bit hash values into 32-bit hash values.
+/// This uses a Murmur3-type mixer "Moremur" from Pelle Evensen.
static inline unsigned combineHashValue(unsigned a, unsigned b) {
- uint64_t key = (uint64_t)a << 32 | (uint64_t)b;
- key += ~(key << 32);
- key ^= (key >> 22);
- key += ~(key << 13);
- key ^= (key >> 8);
- key += (key << 3);
- key ^= (key >> 15);
- key += ~(key << 27);
- key ^= (key >> 31);
- return (unsigned)key;
+ uint64_t x = (uint64_t)a << 32 | (uint64_t)b;
+ x ^= x >> 27;
+ x *= 0x3C79AC492BA7B653UL;
+ x ^= x >> 33;
+ x *= 0x1C69B3F74AC4AE35UL;
+ x ^= x >> 27;
+ return (unsigned)x;
}
} // end namespace detail
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Created using spr 1.3.5-bogner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Created using spr 1.3.5-bogner
DenseMap iteration order is not guaranteed to be deterministic. Without the change, llvm/test/Transforms/GlobalMerge/basic.ll could fail when `combineHashValue` changes (#95970).
DenseMap iteration order is not guaranteed to be deterministic. Without the change, clang/test/Driver/linker-wrapper{,-libs}.c would fail when `combineHashValue` changes (#95970).
Significant stage2-O3:
After #95734 and af82e63 , |
Very nice! |
DenseMap iteration order is not guaranteed to be deterministic. Without the change, llvm/test/Transforms/CodeGenPrepare/X86/statepoint-relocate.ll would fail when `combineHashValue` changes (llvm#95970). Fixes: dba7329
DenseMap iteration order is not guaranteed to be deterministic. Without the change, llvm/test/Transforms/GlobalMerge/basic.ll could fail when `combineHashValue` changes (llvm#95970).
`combineHashValue` is a custom bit mixer from 2008 (5fc8ab6) used for std::pair and std::tuple. It has a long dependency chain and slow. Replace it with a simply multiply-xorshift style hash using a constant from splitmix64[1]. abseil-cpp and carbon also use this style, but with uint128 to probably get a lower avalanche bias. We don't use uint128 for MSVC portability. Measured time to compute [0,1000000000) values on an i7-11850H: * old: 1.163s * new: 0.427s [1]: https://jonkagstrom.com/tuning-bit-mixers/index.html Pull Request: llvm#95970
DenseMap iteration order is not guaranteed to be deterministic. Without the change, clang/test/Driver/linker-wrapper{,-libs}.c would fail when `combineHashValue` changes (llvm#95970).
combineHashValue
is a custom bit mixer from 2008(5fc8ab6) used for std::pair and
std::tuple. It has a long dependency chain and slow. Replace it with
a simply multiply-xorshift style hash using a constant from
splitmix641. abseil-cpp and carbon also use this style, but with
uint128 to probably get a lower avalanche bias. We don't use uint128 for
MSVC portability.
Measured time to compute [0,1000000000) values on an i7-11850H: