[llvm] 61ec4cd - [ADT] Mix the bit width into APInt's hash_value

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 09:18:40 PDT 2020


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 {


        


More information about the llvm-commits mailing list