[ADT] Mix the bit width into APInt's hash_value
authorBenjamin Kramer <benny.kra@googlemail.com>
Tue, 14 Apr 2020 16:13:49 +0000 (18:13 +0200)
committerBenjamin Kramer <benny.kra@googlemail.com>
Tue, 14 Apr 2020 16:16:15 +0000 (18:16 +0200)
Otherwise all zero values from i1 to i64 collide.

llvm/lib/Support/APInt.cpp

index faef9a3..4a591ef 100644 (file)
@@ -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 {