[llvm] 61ec4cd - [ADT] Mix the bit width into APInt's hash_value
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 14 12:31:53 PDT 2020
Why does it matter if they collide? You can't stick two APInts with different widths into a hashtable anyway: the operator== asserts.
-Eli
-----Original Message-----
From: llvm-commits <llvm-commits-bounces at lists.llvm.org> On Behalf Of Benjamin Kramer via llvm-commits
Sent: Tuesday, April 14, 2020 9:19 AM
To: llvm-commits at lists.llvm.org
Subject: [EXT] [llvm] 61ec4cd - [ADT] Mix the bit width into APInt's hash_value
Author: Benjamin Kramer
Date: 2020-04-14T18:16:15+02:00
New Revision: 61ec4cdf6be9f05c65f9cc2e8a1d05320305e9fb
URL: https://github.com/llvm/llvm-project/commit/61ec4cdf6be9f05c65f9cc2e8a1d05320305e9fb
DIFF: https://github.com/llvm/llvm-project/commit/61ec4cdf6be9f05c65f9cc2e8a1d05320305e9fb.diff
LOG: [ADT] Mix the bit width into APInt's hash_value
Otherwise all zero values from i1 to i64 collide.
Added:
Modified:
llvm/lib/Support/APInt.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index faef9a31a0ed..4a591efb141a 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -548,9 +548,11 @@ unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
hash_code llvm::hash_value(const APInt &Arg) {
if (Arg.isSingleWord())
- return hash_combine(Arg.U.VAL);
+ return hash_combine(Arg.BitWidth, Arg.U.VAL);
- return hash_combine_range(Arg.U.pVal, Arg.U.pVal + Arg.getNumWords());
+ return hash_combine(
+ Arg.BitWidth,
+ hash_combine_range(Arg.U.pVal, Arg.U.pVal + Arg.getNumWords()));
}
bool APInt::isSplat(unsigned SplatSizeInBits) const {
_______________________________________________
llvm-commits mailing list
llvm-commits at lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list