<!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>[193437] 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/193437">193437</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-12-04 12:32:21 -0800 (Fri, 04 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[JSC] Use Div and ChillDiv in FTL(B3)Output
https://bugs.webkit.org/show_bug.cgi?id=151844

Patch by Benjamin Poulain &lt;bpoulain@apple.com&gt; on 2015-12-04
Reviewed by Geoffrey Garen.

I copied part of the code of compileArithDiv()
to create a new function FTLOutput::childDiv().

With childDiv() being a concept of FTLOutput,
FTLB3Output was updated accordingly.

* ftl/FTLB3Output.h:
(JSC::FTL::Output::div):
(JSC::FTL::Output::chillDiv):
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::DFG::LowerDFGToLLVM::compileArithDiv):
* ftl/FTLOutput.cpp:
(JSC::FTL::Output::chillDiv):
* ftl/FTLOutput.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLB3Outputh">trunk/Source/JavaScriptCore/ftl/FTLB3Output.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp">trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLOutputcpp">trunk/Source/JavaScriptCore/ftl/FTLOutput.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLOutputh">trunk/Source/JavaScriptCore/ftl/FTLOutput.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (193436 => 193437)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-12-04 20:31:14 UTC (rev 193436)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-12-04 20:32:21 UTC (rev 193437)
</span><span class="lines">@@ -1,5 +1,27 @@
</span><span class="cx"> 2015-12-04  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        [JSC] Use Div and ChillDiv in FTL(B3)Output
+        https://bugs.webkit.org/show_bug.cgi?id=151844
+
+        Reviewed by Geoffrey Garen.
+
+        I copied part of the code of compileArithDiv()
+        to create a new function FTLOutput::childDiv().
+
+        With childDiv() being a concept of FTLOutput,
+        FTLB3Output was updated accordingly.
+
+        * ftl/FTLB3Output.h:
+        (JSC::FTL::Output::div):
+        (JSC::FTL::Output::chillDiv):
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::DFG::LowerDFGToLLVM::compileArithDiv):
+        * ftl/FTLOutput.cpp:
+        (JSC::FTL::Output::chillDiv):
+        * ftl/FTLOutput.h:
+
+2015-12-04  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
</ins><span class="cx">         [JSC] Extend the strength reduction of B3's BitAnd with booleans
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=151852
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLB3Outputh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLB3Output.h (193436 => 193437)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLB3Output.h        2015-12-04 20:31:14 UTC (rev 193436)
+++ trunk/Source/JavaScriptCore/ftl/FTLB3Output.h        2015-12-04 20:32:21 UTC (rev 193437)
</span><span class="lines">@@ -121,7 +121,8 @@
</span><span class="cx">     LValue add(LValue left, LValue right) { return m_block-&gt;appendNew&lt;B3::Value&gt;(m_proc, B3::Add, origin(), left, right); }
</span><span class="cx">     LValue sub(LValue left, LValue right) { return m_block-&gt;appendNew&lt;B3::Value&gt;(m_proc, B3::Sub, origin(), left, right); }
</span><span class="cx">     LValue mul(LValue left, LValue right) { return m_block-&gt;appendNew&lt;B3::Value&gt;(m_proc, B3::Mul, origin(), left, right); }
</span><del>-    LValue div(LValue left, LValue right) { CRASH(); }
</del><ins>+    LValue div(LValue left, LValue right) { return m_block-&gt;appendNew&lt;B3::Value&gt;(m_proc, B3::Div, origin(), left, right); }
+    LValue chillDiv(LValue left, LValue right) { return m_block-&gt;appendNew&lt;B3::Value&gt;(m_proc, B3::ChillDiv, origin(), left, right); }
</ins><span class="cx">     LValue rem(LValue left, LValue right) { CRASH(); }
</span><span class="cx">     LValue neg(LValue value)
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp (193436 => 193437)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2015-12-04 20:31:14 UTC (rev 193436)
+++ trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2015-12-04 20:32:21 UTC (rev 193437)
</span><span class="lines">@@ -1875,88 +1875,49 @@
</span><span class="cx">         case Int32Use: {
</span><span class="cx">             LValue numerator = lowInt32(m_node-&gt;child1());
</span><span class="cx">             LValue denominator = lowInt32(m_node-&gt;child2());
</span><del>-            
-            LBasicBlock unsafeDenominator = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv unsafe denominator&quot;));
-            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv continuation&quot;));
-            LBasicBlock done = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv done&quot;));
-            
-            Vector&lt;ValueFromBlock, 3&gt; results;
-            
-            LValue adjustedDenominator = m_out.add(denominator, m_out.int32One);
-            
-            m_out.branch(
-                m_out.above(adjustedDenominator, m_out.int32One),
-                usually(continuation), rarely(unsafeDenominator));
-            
-            LBasicBlock lastNext = m_out.appendTo(unsafeDenominator, continuation);
-            
-            LValue neg2ToThe31 = m_out.constInt32(-2147483647-1);
-            
-            if (shouldCheckOverflow(m_node-&gt;arithMode())) {
-                LValue cond = m_out.bitOr(m_out.isZero32(denominator), m_out.equal(numerator, neg2ToThe31));
-                speculate(Overflow, noValue(), 0, cond);
-                m_out.jump(continuation);
-            } else {
-                // This is the case where we convert the result to an int after we're done. So,
-                // if the denominator is zero, then the result should be zero.
-                // If the denominator is not zero (i.e. it's -1 because we're guarded by the
-                // check above) and the numerator is -2^31 then the result should be -2^31.
-                
-                LBasicBlock divByZero = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv divide by zero&quot;));
-                LBasicBlock notDivByZero = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv not divide by zero&quot;));
-                LBasicBlock neg2ToThe31ByNeg1 = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv -2^31/-1&quot;));
-                
-                m_out.branch(
-                    m_out.isZero32(denominator), rarely(divByZero), usually(notDivByZero));
-                
-                m_out.appendTo(divByZero, notDivByZero);
-                results.append(m_out.anchor(m_out.int32Zero));
-                m_out.jump(done);
-                
-                m_out.appendTo(notDivByZero, neg2ToThe31ByNeg1);
-                m_out.branch(
-                    m_out.equal(numerator, neg2ToThe31),
-                    rarely(neg2ToThe31ByNeg1), usually(continuation));
-                
-                m_out.appendTo(neg2ToThe31ByNeg1, continuation);
-                results.append(m_out.anchor(neg2ToThe31));
-                m_out.jump(done);
-            }
-            
-            m_out.appendTo(continuation, done);
-            
</del><ins>+
</ins><span class="cx">             if (shouldCheckNegativeZero(m_node-&gt;arithMode())) {
</span><span class="cx">                 LBasicBlock zeroNumerator = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv zero numerator&quot;));
</span><span class="cx">                 LBasicBlock numeratorContinuation = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv numerator continuation&quot;));
</span><del>-                
</del><ins>+
</ins><span class="cx">                 m_out.branch(
</span><span class="cx">                     m_out.isZero32(numerator),
</span><span class="cx">                     rarely(zeroNumerator), usually(numeratorContinuation));
</span><del>-                
</del><ins>+
</ins><span class="cx">                 LBasicBlock innerLastNext = m_out.appendTo(zeroNumerator, numeratorContinuation);
</span><del>-                
</del><ins>+
</ins><span class="cx">                 speculate(
</span><span class="cx">                     NegativeZero, noValue(), 0, m_out.lessThan(denominator, m_out.int32Zero));
</span><del>-                
</del><ins>+
</ins><span class="cx">                 m_out.jump(numeratorContinuation);
</span><del>-                
</del><ins>+
</ins><span class="cx">                 m_out.appendTo(numeratorContinuation, innerLastNext);
</span><span class="cx">             }
</span><span class="cx">             
</span><del>-            LValue result = m_out.div(numerator, denominator);
-            
</del><span class="cx">             if (shouldCheckOverflow(m_node-&gt;arithMode())) {
</span><ins>+                LBasicBlock unsafeDenominator = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv unsafe denominator&quot;));
+                LBasicBlock continuation = FTL_NEW_BLOCK(m_out, (&quot;ArithDiv continuation&quot;));
+
+                LValue adjustedDenominator = m_out.add(denominator, m_out.int32One);
+                m_out.branch(
+                    m_out.above(adjustedDenominator, m_out.int32One),
+                    usually(continuation), rarely(unsafeDenominator));
+
+                LBasicBlock lastNext = m_out.appendTo(unsafeDenominator, continuation);
+                LValue neg2ToThe31 = m_out.constInt32(-2147483647-1);
+                LValue cond = m_out.bitOr(m_out.isZero32(denominator), m_out.equal(numerator, neg2ToThe31));
+                speculate(Overflow, noValue(), 0, cond);
+                m_out.jump(continuation);
+
+                m_out.appendTo(continuation, lastNext);
+                LValue result = m_out.div(numerator, denominator);
</ins><span class="cx">                 speculate(
</span><span class="cx">                     Overflow, noValue(), 0,
</span><span class="cx">                     m_out.notEqual(m_out.mul(result, denominator), numerator));
</span><del>-            }
-            
-            results.append(m_out.anchor(result));
-            m_out.jump(done);
-            
-            m_out.appendTo(done, lastNext);
-            
-            setInt32(m_out.phi(m_out.int32, results));
</del><ins>+                setInt32(result);
+            } else
+                setInt32(m_out.chillDiv(numerator, denominator));
+
</ins><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx">             
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLOutputcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLOutput.cpp (193436 => 193437)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLOutput.cpp        2015-12-04 20:31:14 UTC (rev 193436)
+++ trunk/Source/JavaScriptCore/ftl/FTLOutput.cpp        2015-12-04 20:32:21 UTC (rev 193437)
</span><span class="lines">@@ -75,6 +75,47 @@
</span><span class="cx">     return insertBasicBlock(m_context, m_nextBlock, name);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+LValue Output::chillDiv(LValue numerator, LValue denominator)
+{
+    LBasicBlock unsafeDenominator = FTL_NEW_BLOCK(*this, (&quot;ChillDiv unsafe denominator&quot;));
+    LBasicBlock continuation = FTL_NEW_BLOCK(*this, (&quot;ChillDiv continuation&quot;));
+    LBasicBlock done = FTL_NEW_BLOCK(*this, (&quot;ChillDiv done&quot;));
+    LBasicBlock divByZero = FTL_NEW_BLOCK(*this, (&quot;ChillDiv divide by zero&quot;));
+    LBasicBlock notDivByZero = FTL_NEW_BLOCK(*this, (&quot;ChillDiv not divide by zero&quot;));
+    LBasicBlock neg2ToThe31ByNeg1 = FTL_NEW_BLOCK(*this, (&quot;ArithDiv -2^31/-1&quot;));
+
+    LValue adjustedDenominator = add(denominator, int32One);
+    branch(
+        above(adjustedDenominator, int32One),
+        usually(continuation), rarely(unsafeDenominator));
+
+    Vector&lt;ValueFromBlock, 3&gt; results;
+    LBasicBlock lastNext = appendTo(unsafeDenominator, continuation);
+
+    LValue neg2ToThe31 = constInt32(-2147483647-1);
+    branch(isZero32(denominator), rarely(divByZero), usually(notDivByZero));
+
+    appendTo(divByZero, notDivByZero);
+    results.append(anchor(int32Zero));
+    jump(done);
+
+    appendTo(notDivByZero, neg2ToThe31ByNeg1);
+    branch(equal(numerator, neg2ToThe31),
+        rarely(neg2ToThe31ByNeg1), usually(continuation));
+
+    appendTo(neg2ToThe31ByNeg1, continuation);
+    results.append(anchor(neg2ToThe31));
+    jump(done);
+
+    appendTo(continuation, done);
+    LValue result = div(numerator, denominator);
+    results.append(anchor(result));
+    jump(done);
+
+    appendTo(done, lastNext);
+    return phi(int32, results);
+}
+
</ins><span class="cx"> LValue Output::sensibleDoubleToInt(LValue value)
</span><span class="cx"> {
</span><span class="cx">     RELEASE_ASSERT(isX86());
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLOutputh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLOutput.h (193436 => 193437)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLOutput.h        2015-12-04 20:31:14 UTC (rev 193436)
+++ trunk/Source/JavaScriptCore/ftl/FTLOutput.h        2015-12-04 20:32:21 UTC (rev 193437)
</span><span class="lines">@@ -123,6 +123,7 @@
</span><span class="cx">     LValue sub(LValue left, LValue right) { return buildSub(m_builder, left, right); }
</span><span class="cx">     LValue mul(LValue left, LValue right) { return buildMul(m_builder, left, right); }
</span><span class="cx">     LValue div(LValue left, LValue right) { return buildDiv(m_builder, left, right); }
</span><ins>+    LValue chillDiv(LValue left, LValue right);
</ins><span class="cx">     LValue rem(LValue left, LValue right) { return buildRem(m_builder, left, right); }
</span><span class="cx">     LValue neg(LValue value) { return buildNeg(m_builder, value); }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>