Bug 1114574 - Refactor and improve MCompare::tryFold. r=h4writer
authorJan de Mooij <jdemooij@mozilla.com>
Sat, 27 Dec 2014 13:55:06 +0100
changeset 221418 f8e5c5ed14cb7e871c374f896860cd5c76dd3d4a
parent 221417 2393682aeb6ae35484ca7fd50f185dfa697bae87
child 221419 3f980229dfc19f4ecd26daae0f98e09a42236111
push id28025
push userphilringnalda@gmail.com
push dateSun, 28 Dec 2014 18:49:08 +0000
treeherdermozilla-central@6d5a1e68f248 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersh4writer
bugs1114574
milestone37.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 1114574 - Refactor and improve MCompare::tryFold. r=h4writer
js/src/jit/MIR.cpp
--- a/js/src/jit/MIR.cpp
+++ b/js/src/jit/MIR.cpp
@@ -3035,99 +3035,65 @@ bool
 MCompare::tryFold(bool *result)
 {
     JSOp op = jsop();
 
     if (tryFoldEqualOperands(result))
         return true;
 
     if (compareType_ == Compare_Null || compareType_ == Compare_Undefined) {
-        MOZ_ASSERT(op == JSOP_EQ || op == JSOP_STRICTEQ ||
-                   op == JSOP_NE || op == JSOP_STRICTNE);
-
         // The LHS is the value we want to test against null or undefined.
-        switch (lhs()->type()) {
-          case MIRType_Value:
-            return false;
-          case MIRType_Undefined:
-          case MIRType_Null:
+        if (op == JSOP_STRICTEQ || op == JSOP_STRICTNE) {
             if (lhs()->type() == inputType()) {
-                // Both sides have the same type, null or undefined.
-                *result = (op == JSOP_EQ || op == JSOP_STRICTEQ);
-            } else {
-                // One side is null, the other side is undefined. The result is only
-                // true for loose equality.
-                *result = (op == JSOP_EQ || op == JSOP_STRICTNE);
+                *result = (op == JSOP_STRICTEQ);
+                return true;
+            }
+            if (!lhs()->mightBeType(inputType())) {
+                *result = (op == JSOP_STRICTNE);
+                return true;
             }
-            return true;
-          case MIRType_Object:
-            if ((op == JSOP_EQ || op == JSOP_NE) && operandMightEmulateUndefined())
-                return false;
-            /* FALL THROUGH */
-          case MIRType_Int32:
-          case MIRType_Double:
-          case MIRType_Float32:
-          case MIRType_String:
-          case MIRType_Symbol:
-          case MIRType_Boolean:
-            *result = (op == JSOP_NE || op == JSOP_STRICTNE);
-            return true;
-          default:
-            MOZ_CRASH("Unexpected type");
+        } else {
+            MOZ_ASSERT(op == JSOP_EQ || op == JSOP_NE);
+            if (IsNullOrUndefined(lhs()->type())) {
+                *result = (op == JSOP_EQ);
+                return true;
+            }
+            if (!lhs()->mightBeType(MIRType_Null) &&
+                !lhs()->mightBeType(MIRType_Undefined) &&
+                !operandMightEmulateUndefined())
+            {
+                *result = (op == JSOP_NE);
+                return true;
+            }
         }
+        return false;
     }
 
     if (compareType_ == Compare_Boolean) {
         MOZ_ASSERT(op == JSOP_STRICTEQ || op == JSOP_STRICTNE);
         MOZ_ASSERT(rhs()->type() == MIRType_Boolean);
-
-        switch (lhs()->type()) {
-          case MIRType_Value:
-            return false;
-          case MIRType_Int32:
-          case MIRType_Double:
-          case MIRType_Float32:
-          case MIRType_String:
-          case MIRType_Symbol:
-          case MIRType_Object:
-          case MIRType_Null:
-          case MIRType_Undefined:
+        MOZ_ASSERT(lhs()->type() != MIRType_Boolean, "Should use Int32 comparison");
+
+        if (!lhs()->mightBeType(MIRType_Boolean)) {
             *result = (op == JSOP_STRICTNE);
             return true;
-          case MIRType_Boolean:
-            // Int32 specialization should handle this.
-            MOZ_CRASH("Wrong specialization");
-          default:
-            MOZ_CRASH("Unexpected type");
         }
+        return false;
     }
 
     if (compareType_ == Compare_StrictString) {
         MOZ_ASSERT(op == JSOP_STRICTEQ || op == JSOP_STRICTNE);
         MOZ_ASSERT(rhs()->type() == MIRType_String);
-
-        switch (lhs()->type()) {
-          case MIRType_Value:
-            return false;
-          case MIRType_Boolean:
-          case MIRType_Int32:
-          case MIRType_Double:
-          case MIRType_Float32:
-          case MIRType_Symbol:
-          case MIRType_Object:
-          case MIRType_Null:
-          case MIRType_Undefined:
+        MOZ_ASSERT(lhs()->type() != MIRType_String, "Should use String comparison");
+
+        if (!lhs()->mightBeType(MIRType_String)) {
             *result = (op == JSOP_STRICTNE);
             return true;
-          case MIRType_String:
-            // Compare_String specialization should handle this.
-            MOZ_CRASH("Wrong specialization");
-          default:
-            MOZ_CRASH("Unexpected type");
         }
+        return false;
     }
 
     return false;
 }
 
 bool
 MCompare::evaluateConstantOperands(TempAllocator &alloc, bool *result)
 {