<!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>[192257] 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/192257">192257</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2015-11-10 11:14:49 -0800 (Tue, 10 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[B3] Add more tests for Check and fix bugs this found
https://bugs.webkit.org/show_bug.cgi?id=151073

Reviewed by Saam Barati.

Adds tests for compare/Check fusion. The &quot;MegaCombo&quot; test found a bug in our implementation
of forEachArg: Air::spillEverything() was expecting that the Arg&amp; to point to the actual Arg
so that it can mutate it. But this wasn't the case in B3::CheckSpecial. This fixes that bug.

* b3/B3CheckSpecial.cpp:
(JSC::B3::Air::numB3Args):
(JSC::B3::CheckSpecial::hiddenBranch):
(JSC::B3::CheckSpecial::commitHiddenBranch):
(JSC::B3::CheckSpecial::forEachArg):
* b3/B3CheckSpecial.h:
* b3/testb3.cpp:
(JSC::B3::testSimpleCheck):
(JSC::B3::testCheckLessThan):
(JSC::B3::testCheckMegaCombo):
(JSC::B3::genericTestCompare):
(JSC::B3::run):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3CheckSpecialcpp">trunk/Source/JavaScriptCore/b3/B3CheckSpecial.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3CheckSpecialh">trunk/Source/JavaScriptCore/b3/B3CheckSpecial.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3testb3cpp">trunk/Source/JavaScriptCore/b3/testb3.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (192256 => 192257)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-11-10 18:59:44 UTC (rev 192256)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-11-10 19:14:49 UTC (rev 192257)
</span><span class="lines">@@ -1,5 +1,29 @@
</span><span class="cx"> 2015-11-09  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        [B3] Add more tests for Check and fix bugs this found
+        https://bugs.webkit.org/show_bug.cgi?id=151073
+
+        Reviewed by Saam Barati.
+
+        Adds tests for compare/Check fusion. The &quot;MegaCombo&quot; test found a bug in our implementation
+        of forEachArg: Air::spillEverything() was expecting that the Arg&amp; to point to the actual Arg
+        so that it can mutate it. But this wasn't the case in B3::CheckSpecial. This fixes that bug.
+
+        * b3/B3CheckSpecial.cpp:
+        (JSC::B3::Air::numB3Args):
+        (JSC::B3::CheckSpecial::hiddenBranch):
+        (JSC::B3::CheckSpecial::commitHiddenBranch):
+        (JSC::B3::CheckSpecial::forEachArg):
+        * b3/B3CheckSpecial.h:
+        * b3/testb3.cpp:
+        (JSC::B3::testSimpleCheck):
+        (JSC::B3::testCheckLessThan):
+        (JSC::B3::testCheckMegaCombo):
+        (JSC::B3::genericTestCompare):
+        (JSC::B3::run):
+
+2015-11-09  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
</ins><span class="cx">         [B3] Add a test for CCall with double arguments and results
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=151064
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3CheckSpecialcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3CheckSpecial.cpp (192256 => 192257)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3CheckSpecial.cpp        2015-11-10 18:59:44 UTC (rev 192256)
+++ trunk/Source/JavaScriptCore/b3/B3CheckSpecial.cpp        2015-11-10 19:14:49 UTC (rev 192257)
</span><span class="lines">@@ -45,8 +45,7 @@
</span><span class="cx">     case CheckAdd:
</span><span class="cx">     case CheckSub:
</span><span class="cx">     case CheckMul:
</span><del>-        // ResCond, Tmp, Tmp
-        return 3;
</del><ins>+        return 2;
</ins><span class="cx">     case Check:
</span><span class="cx">         return 1;
</span><span class="cx">     default:
</span><span class="lines">@@ -93,9 +92,19 @@
</span><span class="cx">     return hiddenBranch;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void CheckSpecial::commitHiddenBranch(Inst&amp; original, Inst&amp; hiddenBranch)
+{
+    ASSERT(hiddenBranch.args.size() == m_numCheckArgs);
+    ASSERT(hiddenBranch.opcode = m_checkOpcode);
+    for (unsigned i = 0; i &lt; m_numCheckArgs; ++i)
+        original.args[i + 1] = hiddenBranch.args[i];
+}
+
</ins><span class="cx"> void CheckSpecial::forEachArg(Inst&amp; inst, const ScopedLambda&lt;Inst::EachArgCallback&gt;&amp; callback)
</span><span class="cx"> {
</span><del>-    hiddenBranch(inst).forEachArg(callback);
</del><ins>+    Inst hidden = hiddenBranch(inst);
+    hidden.forEachArg(callback);
+    commitHiddenBranch(inst, hidden);
</ins><span class="cx">     forEachArgImpl(numB3Args(inst), m_numCheckArgs + 1, inst, callback);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3CheckSpecialh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3CheckSpecial.h (192256 => 192257)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3CheckSpecial.h        2015-11-10 18:59:44 UTC (rev 192256)
+++ trunk/Source/JavaScriptCore/b3/B3CheckSpecial.h        2015-11-10 19:14:49 UTC (rev 192257)
</span><span class="lines">@@ -116,6 +116,9 @@
</span><span class="cx">     // Constructs and returns the Inst representing the branch that this will use.
</span><span class="cx">     Air::Inst hiddenBranch(const Air::Inst&amp;) const;
</span><span class="cx"> 
</span><ins>+    // If we edited the hidden branch, this installs the edits into the given inst.
+    void commitHiddenBranch(Air::Inst&amp; original, Air::Inst&amp; hiddenBranch);
+
</ins><span class="cx">     void forEachArg(Air::Inst&amp;, const ScopedLambda&lt;Air::Inst::EachArgCallback&gt;&amp;) override;
</span><span class="cx">     bool isValid(Air::Inst&amp;) override;
</span><span class="cx">     bool admitsStack(Air::Inst&amp;, unsigned argIndex) override;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3testb3cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/testb3.cpp (192256 => 192257)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/testb3.cpp        2015-11-10 18:59:44 UTC (rev 192256)
+++ trunk/Source/JavaScriptCore/b3/testb3.cpp        2015-11-10 19:14:49 UTC (rev 192257)
</span><span class="lines">@@ -2401,6 +2401,95 @@
</span><span class="cx">     CHECK(invoke&lt;int&gt;(*code, 1) == 42);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void testCheckLessThan()
+{
+    Procedure proc;
+    BasicBlock* root = proc.addBlock();
+    Value* arg = root-&gt;appendNew&lt;Value&gt;(
+        proc, Trunc, Origin(),
+        root-&gt;appendNew&lt;ArgumentRegValue&gt;(proc, Origin(), GPRInfo::argumentGPR0));
+    CheckValue* check = root-&gt;appendNew&lt;CheckValue&gt;(
+        proc, Check, Origin(),
+        root-&gt;appendNew&lt;Value&gt;(
+            proc, LessThan, Origin(), arg,
+            root-&gt;appendNew&lt;Const32Value&gt;(proc, Origin(), 42)));
+    check-&gt;setGenerator(
+        [&amp;] (CCallHelpers&amp; jit, const StackmapGenerationParams&amp; params) {
+            CHECK(params.reps.size() == 1);
+            CHECK(params.reps[0].isConstant());
+            CHECK(params.reps[0].value() == 1);
+
+            // This should always work because a function this simple should never have callee
+            // saves.
+            jit.move(CCallHelpers::TrustedImm32(42), GPRInfo::returnValueGPR);
+            jit.emitFunctionEpilogue();
+            jit.ret();
+        });
+    root-&gt;appendNew&lt;ControlValue&gt;(
+        proc, Return, Origin(), root-&gt;appendNew&lt;Const32Value&gt;(proc, Origin(), 0));
+
+    auto code = compile(proc);
+    
+    CHECK(invoke&lt;int&gt;(*code, 42) == 0);
+    CHECK(invoke&lt;int&gt;(*code, 1000) == 0);
+    CHECK(invoke&lt;int&gt;(*code, 41) == 42);
+    CHECK(invoke&lt;int&gt;(*code, 0) == 42);
+    CHECK(invoke&lt;int&gt;(*code, -1) == 42);
+}
+
+void testCheckMegaCombo()
+{
+    Procedure proc;
+    BasicBlock* root = proc.addBlock();
+    Value* base = root-&gt;appendNew&lt;ArgumentRegValue&gt;(proc, Origin(), GPRInfo::argumentGPR0);
+    Value* index = root-&gt;appendNew&lt;Value&gt;(
+        proc, ZExt32, Origin(),
+        root-&gt;appendNew&lt;Value&gt;(
+            proc, Trunc, Origin(),
+            root-&gt;appendNew&lt;ArgumentRegValue&gt;(proc, Origin(), GPRInfo::argumentGPR1)));
+
+    Value* ptr = root-&gt;appendNew&lt;Value&gt;(
+        proc, Add, Origin(), base,
+        root-&gt;appendNew&lt;Value&gt;(
+            proc, Shl, Origin(), index,
+            root-&gt;appendNew&lt;Const32Value&gt;(proc, Origin(), 1)));
+    
+    CheckValue* check = root-&gt;appendNew&lt;CheckValue&gt;(
+        proc, Check, Origin(),
+        root-&gt;appendNew&lt;Value&gt;(
+            proc, LessThan, Origin(),
+            root-&gt;appendNew&lt;MemoryValue&gt;(proc, Load8S, Origin(), ptr),
+            root-&gt;appendNew&lt;Const32Value&gt;(proc, Origin(), 42)));
+    check-&gt;setGenerator(
+        [&amp;] (CCallHelpers&amp; jit, const StackmapGenerationParams&amp; params) {
+            CHECK(params.reps.size() == 1);
+            CHECK(params.reps[0].isConstant());
+            CHECK(params.reps[0].value() == 1);
+
+            // This should always work because a function this simple should never have callee
+            // saves.
+            jit.move(CCallHelpers::TrustedImm32(42), GPRInfo::returnValueGPR);
+            jit.emitFunctionEpilogue();
+            jit.ret();
+        });
+    root-&gt;appendNew&lt;ControlValue&gt;(
+        proc, Return, Origin(), root-&gt;appendNew&lt;Const32Value&gt;(proc, Origin(), 0));
+
+    auto code = compile(proc);
+
+    int8_t value;
+    value = 42;
+    CHECK(invoke&lt;int&gt;(*code, &amp;value - 2, 1) == 0);
+    value = 127;
+    CHECK(invoke&lt;int&gt;(*code, &amp;value - 2, 1) == 0);
+    value = 41;
+    CHECK(invoke&lt;int&gt;(*code, &amp;value - 2, 1) == 42);
+    value = 0;
+    CHECK(invoke&lt;int&gt;(*code, &amp;value - 2, 1) == 42);
+    value = -1;
+    CHECK(invoke&lt;int&gt;(*code, &amp;value - 2, 1) == 42);
+}
+
</ins><span class="cx"> template&lt;typename LeftFunctor, typename RightFunctor&gt;
</span><span class="cx"> void genericTestCompare(
</span><span class="cx">     B3::Opcode opcode, const LeftFunctor&amp; leftFunctor, const RightFunctor&amp; rightFunctor,
</span><span class="lines">@@ -3151,6 +3240,8 @@
</span><span class="cx"> 
</span><span class="cx">     RUN(testSimplePatchpoint());
</span><span class="cx">     RUN(testSimpleCheck());
</span><ins>+    RUN(testCheckLessThan());
+    RUN(testCheckMegaCombo());
</ins><span class="cx"> 
</span><span class="cx">     RUN(testCompare(Equal, 42, 42));
</span><span class="cx">     RUN(testCompare(NotEqual, 42, 42));
</span></span></pre>
</div>
</div>

</body>
</html>