[INFER] Compile x === x on known doubles, bug 619433.
authorBrian Hackett <bhackett1024@gmail.com>
Sun, 06 Mar 2011 20:10:24 -0800
changeset 74722 c9a80630151848598ad2c6be83a84f3e3f936ac5
parent 74721 ada129dc08ad27c3c1d8db8549289fad37ac0045
child 74723 76e248c0dfa7738833b41b9dd79b44642a533596
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
bugs619433
milestone2.0b12pre
[INFER] Compile x === x on known doubles, bug 619433.
js/src/jit-test/tests/jaeger/bug619433-1.js
js/src/methodjit/FastOps.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/jaeger/bug619433-1.js
@@ -0,0 +1,22 @@
+
+/* Test compiling JSOP_STRICTEQ on known doubles. */
+
+function foo(x) {
+  return x === x;
+}
+
+for (var i = 0; i < 20; i++) {
+  assertEq(foo(1.2), true);
+  assertEq(foo(NaN), false);
+}
+
+function bar(x) {
+  if (x === x)
+    return true;
+  return false;
+}
+
+for (var i = 0; i < 20; i++) {
+  assertEq(bar(1.2), true);
+  assertEq(bar(NaN), false);
+}
--- a/js/src/methodjit/FastOps.cpp
+++ b/js/src/methodjit/FastOps.cpp
@@ -1703,16 +1703,30 @@ mjit::Compiler::jsop_stricteq(JSOp op)
         if (lhs->isTypeKnown() && lhs->isNotType(JSVAL_TYPE_DOUBLE)) {
             frame.popn(2);
 
             masm.move(Imm32(op == JSOP_STRICTEQ), result);
             frame.pushTypedPayload(JSVAL_TYPE_BOOLEAN, result);
             return;
         }
 
+        if (lhs->isType(JSVAL_TYPE_DOUBLE)) {
+            FPRegisterID reg = frame.tempFPRegForData(lhs);
+
+            bool equalValue = (op == JSOP_STRICTEQ);
+            masm.move(Imm32(equalValue), result);
+            Jump j = masm.branchDouble(Assembler::DoubleEqual, reg, reg);
+            masm.move(Imm32(!equalValue), result);
+            j.linkTo(masm.label(), &masm);
+
+            frame.popn(2);
+            frame.pushTypedPayload(JSVAL_TYPE_BOOLEAN, result);
+            return;
+        }
+
         /* Assume NaN is in canonical form. */
         RegisterID treg = frame.tempRegForType(lhs);
 
         Assembler::Condition oppositeCond = (op == JSOP_STRICTEQ) ? Assembler::NotEqual : Assembler::Equal;
 
 #if defined JS_CPU_X86 || defined JS_CPU_ARM
         static const int CanonicalNaNType = 0x7FF80000;
         masm.setPtr(oppositeCond, treg, Imm32(CanonicalNaNType), result);