<!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>[205364] 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/205364">205364</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-09-02 12:49:09 -0700 (Fri, 02 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Register usage optimization in mathIC when LHS and RHS are constants isn't configured correctly
https://bugs.webkit.org/show_bug.cgi?id=160802

Patch by Caio Lima &lt;ticaiolima@gmail.com&gt; on 2016-09-02
Reviewed by Saam Barati.

This patch is fixing a broken mechanism of MathIC that avoids allocate
a register to LHS or RHS if one of these operands are proven as valid
constant for JIT*Generator. In previous implementation, even if the
JIT*Generator was not using an operand register because it was proven as a
constant, compileMathIC and emitICFast were allocating a register for
it. This was broken because mathIC-&gt;isLeftOperandValidConstant and
mathIC-&gt;isLeftOperandValidConstant were being called before its Generator be
properly initialized. We changed this mechanism to enable Generators write
their validConstant rules using static methods isLeftOperandValidConstant(SnippetOperand)
and isRightOperandValidConstant(SnippetOperand).

* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileMathIC):
* jit/JITAddGenerator.h:
(JSC::JITAddGenerator::JITAddGenerator):
(JSC::JITAddGenerator::isLeftOperandValidConstant):
(JSC::JITAddGenerator::isRightOperandValidConstant):
* jit/JITArithmetic.cpp:
(JSC::JIT::emitMathICFast):
* jit/JITMathIC.h:
* jit/JITMulGenerator.h:
(JSC::JITMulGenerator::JITMulGenerator):
(JSC::JITMulGenerator::isLeftOperandValidConstant):
(JSC::JITMulGenerator::isRightOperandValidConstant):
* jit/JITSubGenerator.h:
(JSC::JITSubGenerator::isLeftOperandValidConstant):
(JSC::JITSubGenerator::isRightOperandValidConstant):</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="#trunkSourceJavaScriptCorejitJITAddGeneratorh">trunk/Source/JavaScriptCore/jit/JITAddGenerator.h</a></li>
<li><a href="#trunkSourceJavaScriptCorejitJITArithmeticcpp">trunk/Source/JavaScriptCore/jit/JITArithmetic.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorejitJITMathICh">trunk/Source/JavaScriptCore/jit/JITMathIC.h</a></li>
<li><a href="#trunkSourceJavaScriptCorejitJITMulGeneratorh">trunk/Source/JavaScriptCore/jit/JITMulGenerator.h</a></li>
<li><a href="#trunkSourceJavaScriptCorejitJITSubGeneratorh">trunk/Source/JavaScriptCore/jit/JITSubGenerator.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (205363 => 205364)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-09-02 19:42:23 UTC (rev 205363)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-09-02 19:49:09 UTC (rev 205364)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2016-09-02  Caio Lima  &lt;ticaiolima@gmail.com&gt;
+
+        Register usage optimization in mathIC when LHS and RHS are constants isn't configured correctly
+        https://bugs.webkit.org/show_bug.cgi?id=160802
+
+        Reviewed by Saam Barati.
+
+        This patch is fixing a broken mechanism of MathIC that avoids allocate
+        a register to LHS or RHS if one of these operands are proven as valid
+        constant for JIT*Generator. In previous implementation, even if the
+        JIT*Generator was not using an operand register because it was proven as a
+        constant, compileMathIC and emitICFast were allocating a register for
+        it. This was broken because mathIC-&gt;isLeftOperandValidConstant and
+        mathIC-&gt;isLeftOperandValidConstant were being called before its Generator be
+        properly initialized. We changed this mechanism to enable Generators write
+        their validConstant rules using static methods isLeftOperandValidConstant(SnippetOperand)
+        and isRightOperandValidConstant(SnippetOperand).
+
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::compileMathIC):
+        * jit/JITAddGenerator.h:
+        (JSC::JITAddGenerator::JITAddGenerator):
+        (JSC::JITAddGenerator::isLeftOperandValidConstant):
+        (JSC::JITAddGenerator::isRightOperandValidConstant):
+        * jit/JITArithmetic.cpp:
+        (JSC::JIT::emitMathICFast):
+        * jit/JITMathIC.h:
+        * jit/JITMulGenerator.h:
+        (JSC::JITMulGenerator::JITMulGenerator):
+        (JSC::JITMulGenerator::isLeftOperandValidConstant):
+        (JSC::JITMulGenerator::isRightOperandValidConstant):
+        * jit/JITSubGenerator.h:
+        (JSC::JITSubGenerator::isLeftOperandValidConstant):
+        (JSC::JITSubGenerator::isRightOperandValidConstant):
+
</ins><span class="cx"> 2016-09-02  JF Bastien  &lt;jfbastien@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         GetByValWithThis: fix opInfo in DFG creation
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSpeculativeJITcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp (205363 => 205364)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2016-09-02 19:42:23 UTC (rev 205363)
+++ trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2016-09-02 19:49:09 UTC (rev 205364)
</span><span class="lines">@@ -3471,12 +3471,13 @@
</span><span class="cx">         rightOperand.setConstInt32(rightChild-&gt;asInt32());
</span><span class="cx"> 
</span><span class="cx">     ASSERT(!leftOperand.isConst() || !rightOperand.isConst());
</span><ins>+    ASSERT(!(Generator::isLeftOperandValidConstant(leftOperand) &amp;&amp; Generator::isRightOperandValidConstant(rightOperand)));
</ins><span class="cx"> 
</span><del>-    if (!mathIC-&gt;isLeftOperandValidConstant()) {
</del><ins>+    if (!Generator::isLeftOperandValidConstant(leftOperand)) {
</ins><span class="cx">         left = JSValueOperand(this, leftChild);
</span><span class="cx">         leftRegs = left-&gt;jsValueRegs();
</span><span class="cx">     }
</span><del>-    if (!mathIC-&gt;isRightOperandValidConstant()) {
</del><ins>+    if (!Generator::isRightOperandValidConstant(rightOperand)) {
</ins><span class="cx">         right = JSValueOperand(this, rightChild);
</span><span class="cx">         rightRegs = right-&gt;jsValueRegs();
</span><span class="cx">     }
</span><span class="lines">@@ -3511,10 +3512,10 @@
</span><span class="cx"> 
</span><span class="cx">             auto innerLeftRegs = leftRegs;
</span><span class="cx">             auto innerRightRegs = rightRegs;
</span><del>-            if (mathIC-&gt;isLeftOperandValidConstant()) {
</del><ins>+            if (Generator::isLeftOperandValidConstant(leftOperand)) {
</ins><span class="cx">                 innerLeftRegs = resultRegs;
</span><span class="cx">                 m_jit.moveValue(leftChild-&gt;asJSValue(), innerLeftRegs);
</span><del>-            } else if (mathIC-&gt;isRightOperandValidConstant()) {
</del><ins>+            } else if (Generator::isRightOperandValidConstant(rightOperand)) {
</ins><span class="cx">                 innerRightRegs = resultRegs;
</span><span class="cx">                 m_jit.moveValue(rightChild-&gt;asJSValue(), innerRightRegs);
</span><span class="cx">             }
</span><span class="lines">@@ -3542,10 +3543,10 @@
</span><span class="cx"> 
</span><span class="cx">         });
</span><span class="cx">     } else {
</span><del>-        if (mathIC-&gt;isLeftOperandValidConstant()) {
</del><ins>+        if (Generator::isLeftOperandValidConstant(leftOperand)) {
</ins><span class="cx">             left = JSValueOperand(this, leftChild);
</span><span class="cx">             leftRegs = left-&gt;jsValueRegs();
</span><del>-        } else if (mathIC-&gt;isRightOperandValidConstant()) {
</del><ins>+        } else if (Generator::isRightOperandValidConstant(rightOperand)) {
</ins><span class="cx">             right = JSValueOperand(this, rightChild);
</span><span class="cx">             rightRegs = right-&gt;jsValueRegs();
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitJITAddGeneratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/JITAddGenerator.h (205363 => 205364)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/JITAddGenerator.h        2016-09-02 19:42:23 UTC (rev 205363)
+++ trunk/Source/JavaScriptCore/jit/JITAddGenerator.h        2016-09-02 19:49:09 UTC (rev 205364)
</span><span class="lines">@@ -39,8 +39,7 @@
</span><span class="cx"> 
</span><span class="cx"> class JITAddGenerator {
</span><span class="cx"> public:
</span><del>-    JITAddGenerator()
-    { }
</del><ins>+    JITAddGenerator() { }
</ins><span class="cx"> 
</span><span class="cx">     JITAddGenerator(SnippetOperand leftOperand, SnippetOperand rightOperand,
</span><span class="cx">         JSValueRegs result, JSValueRegs left, JSValueRegs right,
</span><span class="lines">@@ -63,8 +62,9 @@
</span><span class="cx">     JITMathICInlineResult generateInline(CCallHelpers&amp;, MathICGenerationState&amp;);
</span><span class="cx">     bool generateFastPath(CCallHelpers&amp;, CCallHelpers::JumpList&amp; endJumpList, CCallHelpers::JumpList&amp; slowPathJumpList, bool shouldEmitProfiling);
</span><span class="cx"> 
</span><del>-    bool isLeftOperandValidConstant() const { return m_leftOperand.isConstInt32(); }
-    bool isRightOperandValidConstant() const { return m_rightOperand.isConstInt32(); }
</del><ins>+    static bool isLeftOperandValidConstant(SnippetOperand leftOperand) { return leftOperand.isPositiveConstInt32(); }
+    static bool isRightOperandValidConstant(SnippetOperand rightOperand) { return rightOperand.isPositiveConstInt32(); }
+    
</ins><span class="cx">     ArithProfile* arithProfile() const { return m_arithProfile; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitJITArithmeticcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/JITArithmetic.cpp (205363 => 205364)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/JITArithmetic.cpp        2016-09-02 19:42:23 UTC (rev 205363)
+++ trunk/Source/JavaScriptCore/jit/JITArithmetic.cpp        2016-09-02 19:49:09 UTC (rev 205364)
</span><span class="lines">@@ -734,9 +734,13 @@
</span><span class="cx"> 
</span><span class="cx">     RELEASE_ASSERT(!leftOperand.isConst() || !rightOperand.isConst());
</span><span class="cx"> 
</span><del>-    if (!mathIC-&gt;isLeftOperandValidConstant())
</del><ins>+    mathIC-&gt;m_generator = Generator(leftOperand, rightOperand, resultRegs, leftRegs, rightRegs, fpRegT0, fpRegT1, scratchGPR, scratchFPR, arithProfile);
+    
+    ASSERT(!(Generator::isLeftOperandValidConstant(leftOperand) &amp;&amp; Generator::isRightOperandValidConstant(rightOperand)));
+    
+    if (!Generator::isLeftOperandValidConstant(leftOperand))
</ins><span class="cx">         emitGetVirtualRegister(op1, leftRegs);
</span><del>-    if (!mathIC-&gt;isRightOperandValidConstant())
</del><ins>+    if (!Generator::isRightOperandValidConstant(rightOperand))
</ins><span class="cx">         emitGetVirtualRegister(op2, rightRegs);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MATH_IC_STATS)
</span><span class="lines">@@ -745,8 +749,6 @@
</span><span class="cx"> 
</span><span class="cx">     MathICGenerationState&amp; mathICGenerationState = m_instructionToMathICGenerationState.add(currentInstruction, MathICGenerationState()).iterator-&gt;value;
</span><span class="cx"> 
</span><del>-    mathIC-&gt;m_generator = Generator(leftOperand, rightOperand, resultRegs, leftRegs, rightRegs, fpRegT0, fpRegT1, scratchGPR, scratchFPR, arithProfile);
-
</del><span class="cx">     bool generatedInlineCode = mathIC-&gt;generateInline(*this, mathICGenerationState);
</span><span class="cx">     if (!generatedInlineCode) {
</span><span class="cx">         if (leftOperand.isConst())
</span><span class="lines">@@ -801,9 +803,11 @@
</span><span class="cx">     else if (isOperandConstantInt(op2))
</span><span class="cx">         rightOperand.setConstInt32(getOperandConstantInt(op2));
</span><span class="cx"> 
</span><del>-    if (mathIC-&gt;isLeftOperandValidConstant())
</del><ins>+    ASSERT(!(Generator::isLeftOperandValidConstant(leftOperand) &amp;&amp; Generator::isRightOperandValidConstant(rightOperand)));
+
+    if (Generator::isLeftOperandValidConstant(leftOperand))
</ins><span class="cx">         emitGetVirtualRegister(op1, leftRegs);
</span><del>-    if (mathIC-&gt;isRightOperandValidConstant())
</del><ins>+    else if (Generator::isRightOperandValidConstant(rightOperand))
</ins><span class="cx">         emitGetVirtualRegister(op2, rightRegs);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MATH_IC_STATS)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitJITMathICh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/JITMathIC.h (205363 => 205364)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/JITMathIC.h        2016-09-02 19:42:23 UTC (rev 205363)
+++ trunk/Source/JavaScriptCore/jit/JITMathIC.h        2016-09-02 19:49:09 UTC (rev 205364)
</span><span class="lines">@@ -58,10 +58,7 @@
</span><span class="cx">     CodeLocationLabel doneLocation() { return m_inlineStart.labelAtOffset(m_inlineSize); }
</span><span class="cx">     CodeLocationLabel slowPathStartLocation() { return m_inlineStart.labelAtOffset(m_deltaFromStartToSlowPathStart); }
</span><span class="cx">     CodeLocationCall slowPathCallLocation() { return m_inlineStart.callAtOffset(m_deltaFromStartToSlowPathCallLocation); }
</span><del>-
-    bool isLeftOperandValidConstant() const { return m_generator.isLeftOperandValidConstant(); }
-    bool isRightOperandValidConstant() const { return m_generator.isRightOperandValidConstant(); }
-
</del><ins>+    
</ins><span class="cx">     bool generateInline(CCallHelpers&amp; jit, MathICGenerationState&amp; state, bool shouldEmitProfiling = true)
</span><span class="cx">     {
</span><span class="cx"> #if CPU(ARM_TRADITIONAL)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitJITMulGeneratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/JITMulGenerator.h (205363 => 205364)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/JITMulGenerator.h        2016-09-02 19:42:23 UTC (rev 205363)
+++ trunk/Source/JavaScriptCore/jit/JITMulGenerator.h        2016-09-02 19:49:09 UTC (rev 205364)
</span><span class="lines">@@ -38,7 +38,8 @@
</span><span class="cx"> 
</span><span class="cx"> class JITMulGenerator {
</span><span class="cx"> public:
</span><del>-    JITMulGenerator() { }
</del><ins>+    JITMulGenerator()
+    { }
</ins><span class="cx"> 
</span><span class="cx">     JITMulGenerator(SnippetOperand leftOperand, SnippetOperand rightOperand,
</span><span class="cx">         JSValueRegs result, JSValueRegs left, JSValueRegs right,
</span><span class="lines">@@ -61,9 +62,9 @@
</span><span class="cx">     JITMathICInlineResult generateInline(CCallHelpers&amp;, MathICGenerationState&amp;);
</span><span class="cx">     bool generateFastPath(CCallHelpers&amp;, CCallHelpers::JumpList&amp; endJumpList, CCallHelpers::JumpList&amp; slowJumpList, bool shouldEmitProfiling);
</span><span class="cx"> 
</span><del>-    bool isLeftOperandValidConstant() const { return m_leftOperand.isPositiveConstInt32(); }
-    bool isRightOperandValidConstant() const { return m_rightOperand.isPositiveConstInt32(); }
-
</del><ins>+    static bool isLeftOperandValidConstant(SnippetOperand leftOperand) { return leftOperand.isPositiveConstInt32(); }
+    static bool isRightOperandValidConstant(SnippetOperand rightOperand) { return rightOperand.isPositiveConstInt32(); }
+    
</ins><span class="cx">     ArithProfile* arithProfile() const { return m_arithProfile; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitJITSubGeneratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/JITSubGenerator.h (205363 => 205364)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/JITSubGenerator.h        2016-09-02 19:42:23 UTC (rev 205363)
+++ trunk/Source/JavaScriptCore/jit/JITSubGenerator.h        2016-09-02 19:49:09 UTC (rev 205364)
</span><span class="lines">@@ -59,8 +59,9 @@
</span><span class="cx">     JITMathICInlineResult generateInline(CCallHelpers&amp;, MathICGenerationState&amp;);
</span><span class="cx">     bool generateFastPath(CCallHelpers&amp;, CCallHelpers::JumpList&amp; endJumpList, CCallHelpers::JumpList&amp; slowPathJumpList, bool shouldEmitProfiling);
</span><span class="cx"> 
</span><del>-    bool isLeftOperandValidConstant() const { return false; }
-    bool isRightOperandValidConstant() const { return false; }
</del><ins>+    static bool isLeftOperandValidConstant(SnippetOperand) { return false; }
+    static bool isRightOperandValidConstant(SnippetOperand) { return false; }
+
</ins><span class="cx">     ArithProfile* arithProfile() const { return m_arithProfile; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre>
</div>
</div>

</body>
</html>