<!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>[195637] 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/195637">195637</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2016-01-26 16:49:03 -0800 (Tue, 26 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>B3's integer range analysis should know that Mul'ing two sufficiently small numbers will yield a number that still has a meaningful range
https://bugs.webkit.org/show_bug.cgi?id=153518

Reviewed by Benjamin Poulain.

Octane/encrypt had an addition overflow check that can be proved away by being sufficiently
sneaky about the analysis of adds, multiplies, and shifts.

I almost added these optimizations to the DFG integer range optimization phase. That phase is
very complicated. B3's integer range analysis is trivial. So I added it to B3. Eventually
we'll want this same machinery in the DFG also.

8% speed-up on Octane/encrypt.

* b3/B3ReduceStrength.cpp:
* b3/B3Value.cpp:
(JSC::B3::Value::dump): Dumping a constant value's name now dumps its value. This makes a huge difference for reading IR.
(JSC::B3::Value::cloneImpl):
(JSC::B3::Value::deepDump):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3ReduceStrengthcpp">trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3Valuecpp">trunk/Source/JavaScriptCore/b3/B3Value.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (195636 => 195637)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-01-27 00:33:33 UTC (rev 195636)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-01-27 00:49:03 UTC (rev 195637)
</span><span class="lines">@@ -1,5 +1,27 @@
</span><span class="cx"> 2016-01-26  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        B3's integer range analysis should know that Mul'ing two sufficiently small numbers will yield a number that still has a meaningful range
+        https://bugs.webkit.org/show_bug.cgi?id=153518
+
+        Reviewed by Benjamin Poulain.
+
+        Octane/encrypt had an addition overflow check that can be proved away by being sufficiently
+        sneaky about the analysis of adds, multiplies, and shifts.
+
+        I almost added these optimizations to the DFG integer range optimization phase. That phase is
+        very complicated. B3's integer range analysis is trivial. So I added it to B3. Eventually
+        we'll want this same machinery in the DFG also.
+
+        8% speed-up on Octane/encrypt.
+
+        * b3/B3ReduceStrength.cpp:
+        * b3/B3Value.cpp:
+        (JSC::B3::Value::dump): Dumping a constant value's name now dumps its value. This makes a huge difference for reading IR.
+        (JSC::B3::Value::cloneImpl):
+        (JSC::B3::Value::deepDump):
+
+2016-01-26  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
</ins><span class="cx">         It should be possible to disable FTL for a range like we disable DFG for a range
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=153511
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3ReduceStrengthcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp (195636 => 195637)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp        2016-01-27 00:33:33 UTC (rev 195636)
+++ trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp        2016-01-27 00:49:03 UTC (rev 195637)
</span><span class="lines">@@ -252,6 +252,102 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    template&lt;typename T&gt;
+    IntRange shl(int32_t shiftAmount)
+    {
+        T newMin = static_cast&lt;T&gt;(m_min) &lt;&lt; shiftAmount;
+        T newMax = static_cast&lt;T&gt;(m_max) &lt;&lt; shiftAmount;
+
+        if ((newMin &gt;&gt; shiftAmount) != static_cast&lt;T&gt;(m_min))
+            newMin = std::numeric_limits&lt;T&gt;::min();
+        if ((newMax &gt;&gt; shiftAmount) != static_cast&lt;T&gt;(m_max))
+            newMax = std::numeric_limits&lt;T&gt;::max();
+
+        return IntRange(newMin, newMax);
+    }
+
+    IntRange shl(int32_t shiftAmount, Type type)
+    {
+        switch (type) {
+        case Int32:
+            return shl&lt;int32_t&gt;(shiftAmount);
+        case Int64:
+            return shl&lt;int64_t&gt;(shiftAmount);
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return IntRange();
+        }
+    }
+
+    template&lt;typename T&gt;
+    IntRange add(const IntRange&amp; other)
+    {
+        if (couldOverflowAdd&lt;T&gt;(other))
+            return top&lt;T&gt;();
+        return IntRange(m_min + other.m_min, m_max + other.m_max);
+    }
+
+    IntRange add(const IntRange&amp; other, Type type)
+    {
+        switch (type) {
+        case Int32:
+            return add&lt;int32_t&gt;(other);
+        case Int64:
+            return add&lt;int64_t&gt;(other);
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return IntRange();
+        }
+    }
+
+    template&lt;typename T&gt;
+    IntRange sub(const IntRange&amp; other)
+    {
+        if (couldOverflowSub&lt;T&gt;(other))
+            return top&lt;T&gt;();
+        return IntRange(m_min - other.m_max, m_max - other.m_min);
+    }
+
+    IntRange sub(const IntRange&amp; other, Type type)
+    {
+        switch (type) {
+        case Int32:
+            return sub&lt;int32_t&gt;(other);
+        case Int64:
+            return sub&lt;int64_t&gt;(other);
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return IntRange();
+        }
+    }
+
+    template&lt;typename T&gt;
+    IntRange mul(const IntRange&amp; other)
+    {
+        if (couldOverflowMul&lt;T&gt;(other))
+            return top&lt;T&gt;();
+        return IntRange(
+            std::min(
+                std::min(m_min * other.m_min, m_min * other.m_max),
+                std::min(m_max * other.m_min, m_max * other.m_max)),
+            std::max(
+                std::max(m_min * other.m_min, m_min * other.m_max),
+                std::max(m_max * other.m_min, m_max * other.m_max)));
+    }
+
+    IntRange mul(const IntRange&amp; other, Type type)
+    {
+        switch (type) {
+        case Int32:
+            return mul&lt;int32_t&gt;(other);
+        case Int64:
+            return mul&lt;int64_t&gt;(other);
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return IntRange();
+        }
+    }
+
</ins><span class="cx"> private:
</span><span class="cx">     int64_t m_min { 0 };
</span><span class="cx">     int64_t m_max { 0 };
</span><span class="lines">@@ -1839,8 +1935,13 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    IntRange rangeFor(Value* value)
</del><ins>+    // FIXME: This should really be a forward analysis. Instead, we uses a bounded-search backwards
+    // analysis.
+    IntRange rangeFor(Value* value, unsigned timeToLive = 5)
</ins><span class="cx">     {
</span><ins>+        if (!timeToLive)
+            return IntRange::top(value-&gt;type());
+        
</ins><span class="cx">         switch (value-&gt;opcode()) {
</span><span class="cx">         case Const32:
</span><span class="cx">         case Const64: {
</span><span class="lines">@@ -1863,6 +1964,24 @@
</span><span class="cx">                 return IntRange::rangeForZShr(value-&gt;child(1)-&gt;asInt32(), value-&gt;type());
</span><span class="cx">             break;
</span><span class="cx"> 
</span><ins>+        case Shl:
+            if (value-&gt;child(1)-&gt;hasInt32())
+                return rangeFor(value-&gt;child(0), timeToLive - 1).shl(
+                    value-&gt;child(1)-&gt;asInt32(), value-&gt;type());
+            break;
+
+        case Add:
+            return rangeFor(value-&gt;child(0), timeToLive - 1).add(
+                rangeFor(value-&gt;child(1), timeToLive - 1), value-&gt;type());
+
+        case Sub:
+            return rangeFor(value-&gt;child(0), timeToLive - 1).sub(
+                rangeFor(value-&gt;child(1), timeToLive - 1), value-&gt;type());
+
+        case Mul:
+            return rangeFor(value-&gt;child(0), timeToLive - 1).mul(
+                rangeFor(value-&gt;child(1), timeToLive - 1), value-&gt;type());
+
</ins><span class="cx">         default:
</span><span class="cx">             break;
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3Valuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3Value.cpp (195636 => 195637)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3Value.cpp        2016-01-27 00:33:33 UTC (rev 195636)
+++ trunk/Source/JavaScriptCore/b3/B3Value.cpp        2016-01-27 00:49:03 UTC (rev 195637)
</span><span class="lines">@@ -111,7 +111,33 @@
</span><span class="cx"> 
</span><span class="cx"> void Value::dump(PrintStream&amp; out) const
</span><span class="cx"> {
</span><ins>+    bool isConstant = false;
+
+    switch (m_opcode) {
+    case Const32:
+        out.print(&quot;$&quot;, asInt32(), &quot;(&quot;);
+        isConstant = true;
+        break;
+    case Const64:
+        out.print(&quot;$&quot;, asInt64(), &quot;(&quot;);
+        isConstant = true;
+        break;
+    case ConstFloat:
+        out.print(&quot;$&quot;, asFloat(), &quot;(&quot;);
+        isConstant = true;
+        break;
+    case ConstDouble:
+        out.print(&quot;$&quot;, asDouble(), &quot;(&quot;);
+        isConstant = true;
+        break;
+    default:
+        break;
+    }
+    
</ins><span class="cx">     out.print(dumpPrefix, m_index);
</span><ins>+
+    if (isConstant)
+        out.print(&quot;)&quot;);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Value* Value::cloneImpl() const
</span><span class="lines">@@ -127,7 +153,7 @@
</span><span class="cx"> 
</span><span class="cx"> void Value::deepDump(const Procedure* proc, PrintStream&amp; out) const
</span><span class="cx"> {
</span><del>-    out.print(m_type, &quot; &quot;, *this, &quot; = &quot;, m_opcode);
</del><ins>+    out.print(m_type, &quot; &quot;, dumpPrefix, m_index, &quot; = &quot;, m_opcode);
</ins><span class="cx"> 
</span><span class="cx">     out.print(&quot;(&quot;);
</span><span class="cx">     CommaPrinter comma;
</span></span></pre>
</div>
</div>

</body>
</html>