<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[186805] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/186805">186805</a></dd>
<dt>Author</dt> <dd>mmirman@apple.com</dd>
<dt>Date</dt> <dd>2015-07-14 10:24:29 -0700 (Tue, 14 Jul 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Makes compileArithSub in the DFG ensure that the constant is an int32.
https://bugs.webkit.org/show_bug.cgi?id=146910
rdar://problem/21729083

Reviewed by Filip Pizlo.

Also fixes the debug build problem where all edges are assumed to
have UntypedUse before the fixup phase.

* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileArithSub):
* dfg/DFGValidate.cpp:
(JSC::DFG::Validate::validateEdgeWithDoubleResultIfNecessary):
* tests/stress/arith-add-with-constants.js: Added some tests for this case.
(arithAdd42WrittenAsInteger):
(testArithAdd42WrittenAsInteger):
(arithSub42WrittenAsDouble):
(testArithSub42WrittenAsDouble):
(doubleConstant):
(testDoubleConstant): Added test for the case of +0.0 and Math.min(0.0)
(arithAdd42WrittenAsDouble): Deleted.
(testArithAdd42WrittenAsDouble): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGSpeculativeJITcpp">trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGValidatecpp">trunk/Source/JavaScriptCore/dfg/DFGValidate.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressarithaddwithconstantsjs">trunk/Source/JavaScriptCore/tests/stress/arith-add-with-constants.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (186804 => 186805)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-07-14 16:16:03 UTC (rev 186804)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-07-14 17:24:29 UTC (rev 186805)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2015-07-13  Matthew Mirman  &lt;mmirman@apple.com&gt;
+
+        Makes compileArithSub in the DFG ensure that the constant is an int32.
+        https://bugs.webkit.org/show_bug.cgi?id=146910
+        rdar://problem/21729083
+
+        Reviewed by Filip Pizlo.
+        
+        Also fixes the debug build problem where all edges are assumed to 
+        have UntypedUse before the fixup phase.
+
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::compileArithSub):
+        * dfg/DFGValidate.cpp:
+        (JSC::DFG::Validate::validateEdgeWithDoubleResultIfNecessary):
+        * tests/stress/arith-add-with-constants.js: Added some tests for this case.
+        (arithAdd42WrittenAsInteger):
+        (testArithAdd42WrittenAsInteger):
+        (arithSub42WrittenAsDouble):
+        (testArithSub42WrittenAsDouble):
+        (doubleConstant):
+        (testDoubleConstant): Added test for the case of +0.0 and Math.min(0.0)
+        (arithAdd42WrittenAsDouble): Deleted.
+        (testArithAdd42WrittenAsDouble): Deleted.
+
</ins><span class="cx"> 2015-07-13  Basile Clement  &lt;basile_clement@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Object cycles should not prevent allocation elimination/sinking
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSpeculativeJITcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp (186804 => 186805)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2015-07-14 16:16:03 UTC (rev 186804)
+++ trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2015-07-14 17:24:29 UTC (rev 186805)
</span><span class="lines">@@ -2989,7 +2989,7 @@
</span><span class="cx">     case Int32Use: {
</span><span class="cx">         ASSERT(!shouldCheckNegativeZero(node-&gt;arithMode()));
</span><span class="cx">         
</span><del>-        if (node-&gt;child2()-&gt;isNumberConstant()) {
</del><ins>+        if (node-&gt;child2()-&gt;isInt32Constant()) {
</ins><span class="cx">             SpeculateInt32Operand op1(this, node-&gt;child1());
</span><span class="cx">             int32_t imm2 = node-&gt;child2()-&gt;asInt32();
</span><span class="cx">             GPRTemporary result(this);
</span><span class="lines">@@ -3006,7 +3006,7 @@
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">             
</span><del>-        if (node-&gt;child1()-&gt;isNumberConstant()) {
</del><ins>+        if (node-&gt;child1()-&gt;isInt32Constant()) {
</ins><span class="cx">             int32_t imm1 = node-&gt;child1()-&gt;asInt32();
</span><span class="cx">             SpeculateInt32Operand op2(this, node-&gt;child2());
</span><span class="cx">             GPRTemporary result(this);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGValidatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGValidate.cpp (186804 => 186805)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGValidate.cpp        2015-07-14 16:16:03 UTC (rev 186804)
+++ trunk/Source/JavaScriptCore/dfg/DFGValidate.cpp        2015-07-14 17:24:29 UTC (rev 186805)
</span><span class="lines">@@ -574,9 +574,9 @@
</span><span class="cx">             return;
</span><span class="cx"> 
</span><span class="cx">         if (m_graph.m_planStage &lt; PlanStage::AfterFixup)
</span><del>-            VALIDATE((node, edge), edge.useKind() == UntypedUse);
-        else
-            VALIDATE((node, edge), edge.useKind() == DoubleRepUse || edge.useKind() == DoubleRepRealUse || edge.useKind() == DoubleRepMachineIntUse);
</del><ins>+            return;
+        
+        VALIDATE((node, edge), edge.useKind() == DoubleRepUse || edge.useKind() == DoubleRepRealUse || edge.useKind() == DoubleRepMachineIntUse);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     void checkOperand(
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressarithaddwithconstantsjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tests/stress/arith-add-with-constants.js (186804 => 186805)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/arith-add-with-constants.js        2015-07-14 16:16:03 UTC (rev 186804)
+++ trunk/Source/JavaScriptCore/tests/stress/arith-add-with-constants.js        2015-07-14 17:24:29 UTC (rev 186805)
</span><span class="lines">@@ -167,56 +167,105 @@
</span><span class="cx"> testArithAdd42WrittenAsInteger();
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-function arithAdd42WrittenAsDouble(x) {
-    var a = x + 42.0;
-    var b = 42. + x;
</del><ins>+
+
+// Test &quot;value + 42&quot;.
+function arithAdd42WrittenAsInteger(x) {
+    var a = x + 42;
+    var b = 42 + x;
</ins><span class="cx">     if (!(isNaN(x) &amp;&amp; isNaN(a) &amp;&amp; isNaN(b)) &amp;&amp; a !== b)
</span><del>-        throw &quot;Internal error on arithAdd42WrittenAsDouble, a = &quot; + a + &quot; b = &quot; + b;
</del><ins>+        throw &quot;Internal error on arithAdd42WrittenAsInteger, a = &quot; + a + &quot; b = &quot; + b;
</ins><span class="cx">     return a;
</span><span class="cx"> }
</span><del>-noInline(arithAdd42WrittenAsDouble);
</del><ins>+noInline(arithAdd42WrittenAsInteger);
</ins><span class="cx"> 
</span><del>-function testArithAdd42WrittenAsDouble() {
</del><ins>+function testArithAdd42WrittenAsInteger() {
</ins><span class="cx">     for (var i = 0; i &lt; 1e4; ++i) {
</span><del>-        var result = arithAdd42WrittenAsDouble(13);
</del><ins>+        var result = arithAdd42WrittenAsInteger(13);
</ins><span class="cx">         if (result !== 55) {
</span><del>-            throw &quot;arithAdd42WrittenAsDouble(i) = &quot; + result + &quot;, expected 55&quot;;
</del><ins>+            throw &quot;arithAdd42WrittenAsInteger(13) = &quot; + result + &quot;, expected 55&quot;;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (var i = 0; i &lt; 1e4; ++i) {
</span><del>-        var result = arithAdd42WrittenAsDouble(-0);
</del><ins>+        var result = arithAdd42WrittenAsInteger(-0);
</ins><span class="cx">         if (result !== 42) {
</span><del>-            throw &quot;arithAdd42WrittenAsDouble(-0) = &quot; + result + &quot;, expected 42&quot;;
</del><ins>+            throw &quot;arithAdd42WrittenAsInteger(-0) = &quot; + result + &quot;, expected 42&quot;;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (var i = 0; i &lt; 1e4; ++i) {
</span><del>-        var result = arithAdd42WrittenAsDouble(13.3);
</del><ins>+        var result = arithAdd42WrittenAsInteger(13.3);
</ins><span class="cx">         if (result !== 55.3) {
</span><del>-            throw &quot;arithAdd42WrittenAsDouble(13.3) = &quot; + result + &quot;, expected 55.3&quot;;
</del><ins>+            throw &quot;arithAdd42WrittenAsInteger(13.3) = &quot; + result + &quot;, expected 55.3&quot;;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (var i = 0; i &lt; 1e4; ++i) {;
</span><del>-        var result = arithAdd42WrittenAsDouble(NaN);
</del><ins>+        var result = arithAdd42WrittenAsInteger(NaN);
</ins><span class="cx">         if (!isNaN(result)) {
</span><del>-            throw &quot;arithAdd42WrittenAsDouble(NaN) = &quot; + result + &quot;, expected NaN&quot;;
</del><ins>+            throw &quot;arithAdd42WrittenAsInteger(NaN) = &quot; + result + &quot;, expected NaN&quot;;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (var i = 0; i &lt; 1e4; ++i) {;
</span><del>-        var result = arithAdd42WrittenAsDouble(Infinity);
</del><ins>+        var result = arithAdd42WrittenAsInteger(Infinity);
</ins><span class="cx">         if (isFinite(result)) {
</span><del>-            throw &quot;arithAdd42WrittenAsDouble(Infinity) = &quot; + result + &quot;, expected Infinity&quot;;
</del><ins>+            throw &quot;arithAdd42WrittenAsInteger(Infinity) = &quot; + result + &quot;, expected Infinity&quot;;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (var i = 0; i &lt; 1e4; ++i) {;
</span><del>-        var result = arithAdd42WrittenAsDouble(-Infinity);
</del><ins>+        var result = arithAdd42WrittenAsInteger(-Infinity);
</ins><span class="cx">         if (isFinite(result) || result &gt;= 0) {
</span><del>-            throw &quot;arithAdd42WrittenAsDouble(-Infinity) = &quot; + result + &quot;, expected -Infinity&quot;;
</del><ins>+            throw &quot;arithAdd42WrittenAsInteger(-Infinity) = &quot; + result + &quot;, expected -Infinity&quot;;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> }
</span><del>-testArithAdd42WrittenAsDouble();
</del><span class="cx">\ No newline at end of file
</span><ins>+testArithAdd42WrittenAsInteger();
+
+function arithSub42WrittenAsDouble(x) {
+    var a = (x|0) - 42.0;
+    var b = -42. + (x|0);
+    if (!(isNaN(x) &amp;&amp; isNaN(a) &amp;&amp; isNaN(b)) &amp;&amp; a !== b)
+        throw &quot;Internal error on arithSub42WrittenAsDouble, a = &quot; + a + &quot; b = &quot; + b;
+    return a;
+}
+noInline(arithSub42WrittenAsDouble);
+
+function testArithSub42WrittenAsDouble() {
+    for (var i = 0; i &lt; 1e4; ++i) {
+        var result = arithSub42WrittenAsDouble(13);
+        if (result !== -29) {
+            throw &quot;arithSub42WrittenAsDouble(13) = &quot; + result + &quot;, expected -29&quot;;
+        }
+    }
+
+    for (var i = 0; i &lt; 1e4; ++i) {
+        var result = arithSub42WrittenAsDouble(-0);
+        if (result !== -42) {
+            throw &quot;arithSub42WrittenAsDouble(-0) = &quot; + result + &quot;, expected -42&quot;;
+        }
+    }
+
+    for (var i = 0; i &lt; 1e4; ++i) {
+        var result = arithSub42WrittenAsDouble(13.3);
+        if (result !== -29) {
+            throw &quot;arithSub42WrittenAsDouble(13.3) = &quot; + result + &quot;, expected -29&quot;;
+        }
+    }
+}
+testArithSub42WrittenAsDouble();
+
+
+function doubleConstant(){
+    Math.min(0.0);
+    +0.0;
+} noInline(doubleConstant);
+
+function testDoubleConstant(){
+    for (var i = 0; i &lt; 1e4; ++i) {
+        doubleConstant();
+    }
+}
+testDoubleConstant();
</ins></span></pre>
</div>
</div>

</body>
</html>