Title: [199639] trunk/Source/_javascript_Core
Revision
199639
Author
[email protected]
Date
2016-04-16 21:55:02 -0700 (Sat, 16 Apr 2016)

Log Message

[JSC] DFG should support relational comparisons of Number and Other
https://bugs.webkit.org/show_bug.cgi?id=156669

Patch by Benjamin Poulain <[email protected]> on 2016-04-16
Reviewed by Darin Adler.

In Sunspider/3d-raytrace, DFG falls back to JSValue in some important
relational compare because profiling sees "undefined" from time to time.

This case is fairly common outside Sunspider too because of out-of-bounds array access.
Unfortunately for us, our fallback for compare is really inefficient.

Fortunately, relational comparison with null/undefined/true/false are trival.
We can just convert both side to Double. That's what this patch adds.

I also extended constant folding for those cases because I noticed
a bunch of "undefined" constant going through DoubleRep at runtime.

* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
* tests/stress/compare-number-and-other.js: Added.
(opaqueSideEffect):
(let.operator.of.operators.eval.testPolymorphic):
(let.operator.of.operators.let.left.of.typeCases.let.right.of.typeCases.eval.testMonomorphic):
(let.operator.of.operators.let.left.of.typeCases.let.right.of.typeCases.testMonomorphicLeftConstant):
(let.operator.of.operators.let.left.of.typeCases.let.right.of.typeCases.testMonomorphicRightConstant):
(let.operator.of.operators.let.left.of.typeCases.let.right.of.typeCases.i.testPolymorphic):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (199638 => 199639)


--- trunk/Source/_javascript_Core/ChangeLog	2016-04-17 03:44:52 UTC (rev 199638)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-04-17 04:55:02 UTC (rev 199639)
@@ -1,3 +1,34 @@
+2016-04-16  Benjamin Poulain  <[email protected]>
+
+        [JSC] DFG should support relational comparisons of Number and Other
+        https://bugs.webkit.org/show_bug.cgi?id=156669
+
+        Reviewed by Darin Adler.
+
+        In Sunspider/3d-raytrace, DFG falls back to JSValue in some important
+        relational compare because profiling sees "undefined" from time to time.
+
+        This case is fairly common outside Sunspider too because of out-of-bounds array access.
+        Unfortunately for us, our fallback for compare is really inefficient.
+
+        Fortunately, relational comparison with null/undefined/true/false are trival.
+        We can just convert both side to Double. That's what this patch adds.
+
+        I also extended constant folding for those cases because I noticed
+        a bunch of "undefined" constant going through DoubleRep at runtime.
+
+        * dfg/DFGAbstractInterpreterInlines.h:
+        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
+        * dfg/DFGFixupPhase.cpp:
+        (JSC::DFG::FixupPhase::fixupNode):
+        * tests/stress/compare-number-and-other.js: Added.
+        (opaqueSideEffect):
+        (let.operator.of.operators.eval.testPolymorphic):
+        (let.operator.of.operators.let.left.of.typeCases.let.right.of.typeCases.eval.testMonomorphic):
+        (let.operator.of.operators.let.left.of.typeCases.let.right.of.typeCases.testMonomorphicLeftConstant):
+        (let.operator.of.operators.let.left.of.typeCases.let.right.of.typeCases.testMonomorphicRightConstant):
+        (let.operator.of.operators.let.left.of.typeCases.let.right.of.typeCases.i.testPolymorphic):
+
 2016-04-16  Benjamin Poulain  <[email protected]>
 
         [JSC] FRound/Negate can produce an impure NaN out of a pure NaN

Modified: trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h (199638 => 199639)


--- trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2016-04-17 03:44:52 UTC (rev 199638)
+++ trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2016-04-17 04:55:02 UTC (rev 199639)
@@ -392,9 +392,23 @@
         
     case DoubleRep: {
         JSValue child = forNode(node->child1()).value();
-        if (child && child.isNumber()) {
-            setConstant(node, jsDoubleNumber(child.asNumber()));
-            break;
+        if (child) {
+            if (child.isNumber()) {
+                setConstant(node, jsDoubleNumber(child.asNumber()));
+                break;
+            }
+            if (child.isUndefined()) {
+                setConstant(node, jsDoubleNumber(PNaN));
+                break;
+            }
+            if (child.isNull() || child.isFalse()) {
+                setConstant(node, jsDoubleNumber(0));
+                break;
+            }
+            if (child.isTrue()) {
+                setConstant(node, jsDoubleNumber(1));
+                break;
+            }
         }
 
         SpeculatedType type = forNode(node->child1()).m_type;

Modified: trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp (199638 => 199639)


--- trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp	2016-04-17 03:44:52 UTC (rev 199638)
+++ trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp	2016-04-17 04:55:02 UTC (rev 199639)
@@ -453,6 +453,18 @@
             if (Node::shouldSpeculateNumberOrBoolean(node->child1().node(), node->child2().node())) {
                 fixDoubleOrBooleanEdge(node->child1());
                 fixDoubleOrBooleanEdge(node->child2());
+            }
+            if (node->op() != CompareEq
+                && node->child1()->shouldSpeculateNotCell()
+                && node->child2()->shouldSpeculateNotCell()) {
+                if (node->child1()->shouldSpeculateNumberOrBoolean())
+                    fixDoubleOrBooleanEdge(node->child1());
+                else
+                    fixEdge<DoubleRepUse>(node->child1());
+                if (node->child2()->shouldSpeculateNumberOrBoolean())
+                    fixDoubleOrBooleanEdge(node->child2());
+                else
+                    fixEdge<DoubleRepUse>(node->child2());
                 node->clearFlags(NodeMustGenerate);
                 break;
             }

Added: trunk/Source/_javascript_Core/tests/stress/compare-number-and-other.js (0 => 199639)


--- trunk/Source/_javascript_Core/tests/stress/compare-number-and-other.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/compare-number-and-other.js	2016-04-17 04:55:02 UTC (rev 199639)
@@ -0,0 +1,75 @@
+let typeCases = [
+    "1",
+    "Math.PI",
+    "NaN",
+    "undefined",
+    "null",
+    "true",
+    "false",
+];
+
+let operators = ["<", "<=", ">", ">=", "==", "!=", "===", "!=="];
+
+function opaqueSideEffect()
+{
+}
+noInline(opaqueSideEffect);
+
+let testCaseIndex = 0;
+for (let operator of operators) {
+    eval(`
+        function testPolymorphic(a, b) {
+            if (a ${operator} b) {
+                opaqueSideEffect()
+                return true;
+            }
+            return false;
+        }
+        noInline(testPolymorphic)`);
+
+    for (let left of typeCases) {
+        for (let right of typeCases) {
+            let llintResult = eval(left + operator + right);
+            eval(`
+            function testMonomorphic${testCaseIndex}(a, b) {
+                if (a ${operator} b) {
+                    opaqueSideEffect()
+                    return true;
+                }
+                return false;
+            }
+            noInline(testMonomorphic${testCaseIndex});
+
+            function testMonomorphicLeftConstant${testCaseIndex}(b) {
+                if (${left} ${operator} b) {
+                    opaqueSideEffect()
+                    return true;
+                }
+                return false;
+            }
+            noInline(testMonomorphicLeftConstant${testCaseIndex});
+
+            function testMonomorphicRightConstant${testCaseIndex}(a) {
+                if (a ${operator} ${right}) {
+                    opaqueSideEffect()
+                    return true;
+                }
+                return false;
+            }
+            noInline(testMonomorphicRightConstant${testCaseIndex});
+
+            for (let i = 0; i < 500; ++i) {
+                if (testMonomorphic${testCaseIndex}(${left}, ${right}) != ${llintResult})
+                    throw "Failed testMonomorphic${testCaseIndex}(${left}, ${right})";
+                if (testMonomorphicLeftConstant${testCaseIndex}(${right}) != ${llintResult})
+                    throw "Failed testMonomorphicLeftConstant${testCaseIndex}(${right})";
+                if (testMonomorphicRightConstant${testCaseIndex}(${left}) != ${llintResult})
+                    throw "Failed testMonomorphicLeftConstant${testCaseIndex}(${left})";
+                if (testPolymorphic(${left}, ${right}) !== ${llintResult})
+                    throw "Failed polymorphicVersion(${left})";
+            }
+            `);
+            ++testCaseIndex;
+        }
+    }
+}
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to