Bug 1058075 - IonMonkey: GVN: Fix MConstant's hash function to reduce collisions r=mjrosenb
authorDan Gohman <sunfish@mozilla.com>
Mon, 25 Aug 2014 15:03:23 -0700
changeset 201599 73d25b34ba67c8ee87c3dc555e8e00206f0638e1
parent 201598 dbd56f218adcfd06e71e5387970be610f2528e27
child 201600 949cf26ba3d5cb6ed17ba5fb626be29051a099ab
push id27375
push userryanvm@gmail.com
push dateTue, 26 Aug 2014 19:56:59 +0000
treeherdermozilla-central@f9bfe115fee5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmjrosenb
bugs1058075
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1058075 - IonMonkey: GVN: Fix MConstant's hash function to reduce collisions r=mjrosenb
js/src/jit/MIR.cpp
--- a/js/src/jit/MIR.cpp
+++ b/js/src/jit/MIR.cpp
@@ -537,20 +537,24 @@ MConstant::MConstant(JSObject *obj)
 {
     setResultType(MIRType_Object);
     setMovable();
 }
 
 HashNumber
 MConstant::valueHash() const
 {
-    // This disregards some state, since values are 64 bits. But for a hash,
-    // it's completely acceptable.
-    return (HashNumber)JSVAL_TO_IMPL(value_).asBits;
+    // Fold all 64 bits into the 32-bit result. It's tempting to just discard
+    // half of the bits, as this is just a hash, however there are many common
+    // patterns of values where only the low or the high bits vary, so
+    // discarding either side would lead to excessive hash collisions.
+    uint64_t bits = JSVAL_TO_IMPL(value_).asBits;
+    return (HashNumber)bits ^ (HashNumber)(bits >> 32);
 }
+
 bool
 MConstant::congruentTo(const MDefinition *ins) const
 {
     if (!ins->isConstant())
         return false;
     return ins->toConstant()->value() == value();
 }