<!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>[161683] branches/jsCStack/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/161683">161683</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2014-01-10 15:17:57 -0800 (Fri, 10 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>DFG should insert Phantoms when it uses conversion nodes
https://bugs.webkit.org/show_bug.cgi?id=126777
Reviewed by Oliver Hunt.
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
(JSC::DFG::FixupPhase::fixupSetLocalsInBlock):
(JSC::DFG::FixupPhase::fixupUntypedSetLocalsInBlock):
(JSC::DFG::FixupPhase::fixEdge):
(JSC::DFG::FixupPhase::fixIntEdge):
(JSC::DFG::FixupPhase::injectInt32ToDoubleNode):
(JSC::DFG::FixupPhase::addPhantomsIfNecessary):
* dfg/DFGNodeFlags.cpp:
(JSC::DFG::dumpNodeFlags):
* dfg/DFGValidate.cpp:
(JSC::DFG::Validate::validate):
* tests/stress/exit-after-int32-to-double.js: Added.
(foo):
* tests/stress/exit-after-int52-to-double.js: Added.
(foo):
* tests/stress/exit-after-int52-to-value.js: Added.
(foo):
(makeWeirdObject):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesjsCStackSourceJavaScriptCoreChangeLog">branches/jsCStack/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoredfgDFGCFGSimplificationPhasecpp">branches/jsCStack/Source/JavaScriptCore/dfg/DFGCFGSimplificationPhase.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoredfgDFGFixupPhasecpp">branches/jsCStack/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoredfgDFGNodeFlagscpp">branches/jsCStack/Source/JavaScriptCore/dfg/DFGNodeFlags.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoredfgDFGValidatecpp">branches/jsCStack/Source/JavaScriptCore/dfg/DFGValidate.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressexitafterint32todoublejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int32-to-double.js</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressexitafterint52todoublejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int52-to-double.js</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressexitafterint52tovaluejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int52-to-value.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesjsCStackSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ChangeLog (161682 => 161683)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ChangeLog        2014-01-10 22:54:16 UTC (rev 161682)
+++ branches/jsCStack/Source/JavaScriptCore/ChangeLog        2014-01-10 23:17:57 UTC (rev 161683)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2014-01-10 Filip Pizlo <fpizlo@apple.com>
+
+ DFG should insert Phantoms when it uses conversion nodes
+ https://bugs.webkit.org/show_bug.cgi?id=126777
+
+ Reviewed by Oliver Hunt.
+
+ * dfg/DFGFixupPhase.cpp:
+ (JSC::DFG::FixupPhase::fixupNode):
+ (JSC::DFG::FixupPhase::fixupSetLocalsInBlock):
+ (JSC::DFG::FixupPhase::fixupUntypedSetLocalsInBlock):
+ (JSC::DFG::FixupPhase::fixEdge):
+ (JSC::DFG::FixupPhase::fixIntEdge):
+ (JSC::DFG::FixupPhase::injectInt32ToDoubleNode):
+ (JSC::DFG::FixupPhase::addPhantomsIfNecessary):
+ * dfg/DFGNodeFlags.cpp:
+ (JSC::DFG::dumpNodeFlags):
+ * dfg/DFGValidate.cpp:
+ (JSC::DFG::Validate::validate):
+ * tests/stress/exit-after-int32-to-double.js: Added.
+ (foo):
+ * tests/stress/exit-after-int52-to-double.js: Added.
+ (foo):
+ * tests/stress/exit-after-int52-to-value.js: Added.
+ (foo):
+ (makeWeirdObject):
+
</ins><span class="cx"> 2014-01-09 Mark Lam <mark.lam@apple.com>
</span><span class="cx">
</span><span class="cx"> Merge trunk r161446.
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoredfgDFGCFGSimplificationPhasecpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/dfg/DFGCFGSimplificationPhase.cpp (161682 => 161683)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/dfg/DFGCFGSimplificationPhase.cpp        2014-01-10 22:54:16 UTC (rev 161682)
+++ branches/jsCStack/Source/JavaScriptCore/dfg/DFGCFGSimplificationPhase.cpp        2014-01-10 23:17:57 UTC (rev 161683)
</span><span class="lines">@@ -79,6 +79,8 @@
</span><span class="cx"> // suboptimal, because if my successor has multiple predecessors then we'll
</span><span class="cx"> // be keeping alive things on other predecessor edges unnecessarily.
</span><span class="cx"> // What we really need is the notion of end-of-block ghosties!
</span><ins>+ // FIXME: Allow putting phantoms after terminals.
+ // https://bugs.webkit.org/show_bug.cgi?id=126778
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoredfgDFGFixupPhasecpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp (161682 => 161683)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp        2014-01-10 22:54:16 UTC (rev 161682)
+++ branches/jsCStack/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp        2014-01-10 23:17:57 UTC (rev 161683)
</span><span class="lines">@@ -100,12 +100,14 @@
</span><span class="cx"> case BitRShift:
</span><span class="cx"> case BitLShift:
</span><span class="cx"> case BitURShift: {
</span><del>- fixBinaryIntEdges();
</del><ins>+ fixIntEdge(node->child1());
+ fixIntEdge(node->child2());
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> case ArithIMul: {
</span><del>- fixBinaryIntEdges();
</del><ins>+ fixIntEdge(node->child1());
+ fixIntEdge(node->child2());
</ins><span class="cx"> node->setOp(ArithMul);
</span><span class="cx"> node->setArithMode(Arith::Unchecked);
</span><span class="cx"> node->child1().setUseKind(Int32Use);
</span><span class="lines">@@ -980,6 +982,19 @@
</span><span class="cx">
</span><span class="cx"> if (!node->containsMovHint())
</span><span class="cx"> DFG_NODE_DO_TO_CHILDREN(m_graph, node, observeUntypedEdge);
</span><ins>+
+ if (node->isTerminal()) {
+ // Terminal nodes don't need post-phantoms, and inserting them would violate
+ // the current requirement that a terminal is the last thing in a block. We
+ // should eventually change that requirement but even if we did, this would
+ // still be a valid optimization. All terminals accept just one input, and
+ // if that input is a conversion node then no further speculations will be
+ // performed.
+ // FIXME: Get rid of this by allowing Phantoms after terminals.
+ // https://bugs.webkit.org/show_bug.cgi?id=126778
+ m_requiredPhantoms.resize(0);
+ } else
+ addPhantomsIfNecessary();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void observeUntypedEdge(Node*, Edge& edge)
</span><span class="lines">@@ -1265,6 +1280,7 @@
</span><span class="cx"> RELEASE_ASSERT_NOT_REACHED();
</span><span class="cx"> break;
</span><span class="cx"> }
</span><ins>+ addPhantomsIfNecessary();
</ins><span class="cx"> }
</span><span class="cx"> m_insertionSet.execute(block);
</span><span class="cx"> }
</span><span class="lines">@@ -1280,8 +1296,10 @@
</span><span class="cx"> if (node->op() != SetLocal)
</span><span class="cx"> continue;
</span><span class="cx">
</span><del>- if (node->child1().useKind() == UntypedUse)
</del><ins>+ if (node->child1().useKind() == UntypedUse) {
</ins><span class="cx"> fixEdge<UntypedUse>(node->child1());
</span><ins>+ addPhantomsIfNecessary();
+ }
</ins><span class="cx"> }
</span><span class="cx"> m_insertionSet.execute(block);
</span><span class="cx"> }
</span><span class="lines">@@ -1455,6 +1473,7 @@
</span><span class="cx"> // Int8ToDouble will convert int52's that fit in an int32 into a double
</span><span class="cx"> // rather than trying to create a boxed int32 like Int52ToValue does.
</span><span class="cx">
</span><ins>+ m_requiredPhantoms.append(edge.node());
</ins><span class="cx"> Node* result = m_insertionSet.insertNode(
</span><span class="cx"> m_indexInBlock, SpecInt52AsDouble, Int52ToDouble,
</span><span class="cx"> m_currentNode->codeOrigin, Edge(edge.node(), NumberUse));
</span><span class="lines">@@ -1508,6 +1527,7 @@
</span><span class="cx"> //
</span><span class="cx"> // But the solution we use handles the above gracefully.
</span><span class="cx">
</span><ins>+ m_requiredPhantoms.append(edge.node());
</ins><span class="cx"> Node* result = m_insertionSet.insertNode(
</span><span class="cx"> m_indexInBlock, SpecInt52, Int52ToValue,
</span><span class="cx"> m_currentNode->codeOrigin, Edge(edge.node(), UntypedUse));
</span><span class="lines">@@ -1520,12 +1540,12 @@
</span><span class="cx"> edge.setUseKind(useKind);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- bool fixIntEdge(Edge& edge)
</del><ins>+ void fixIntEdge(Edge& edge)
</ins><span class="cx"> {
</span><span class="cx"> Node* node = edge.node();
</span><span class="cx"> if (node->shouldSpeculateInt32()) {
</span><span class="cx"> fixEdge<Int32Use>(edge);
</span><del>- return false;
</del><ins>+ return;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> UseKind useKind;
</span><span class="lines">@@ -1543,24 +1563,13 @@
</span><span class="cx"> observeUseKindOnNode(node, useKind);
</span><span class="cx">
</span><span class="cx"> edge = Edge(newNode, KnownInt32Use);
</span><del>- return true;
</del><ins>+ m_requiredPhantoms.append(node);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- void fixBinaryIntEdges()
</del><ins>+ void injectInt32ToDoubleNode(Edge& edge, UseKind useKind = NumberUse)
</ins><span class="cx"> {
</span><del>- AdjacencyList children = m_currentNode->children;
</del><ins>+ m_requiredPhantoms.append(edge.node());
</ins><span class="cx">
</span><del>- // Call fixIntEdge() on both edges.
- bool needPhantom =
- fixIntEdge(m_currentNode->child1()) | fixIntEdge(m_currentNode->child2());
-
- if (!needPhantom)
- return;
- m_insertionSet.insertNode(m_indexInBlock + 1, SpecNone, Phantom, m_currentNode->codeOrigin, children);
- }
-
- void injectInt32ToDoubleNode(Edge& edge, UseKind useKind = NumberUse)
- {
</del><span class="cx"> Node* result = m_insertionSet.insertNode(
</span><span class="cx"> m_indexInBlock, SpecInt52AsDouble, Int32ToDouble,
</span><span class="cx"> m_currentNode->codeOrigin, Edge(edge.node(), NumberUse));
</span><span class="lines">@@ -1746,12 +1755,27 @@
</span><span class="cx"> fixEdge<KnownCellUse>(node->child1());
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><ins>+
+ void addPhantomsIfNecessary()
+ {
+ if (m_requiredPhantoms.isEmpty())
+ return;
+
+ for (unsigned i = m_requiredPhantoms.size(); i--;) {
+ m_insertionSet.insertNode(
+ m_indexInBlock + 1, SpecNone, Phantom, m_currentNode->codeOrigin,
+ Edge(m_requiredPhantoms[i], UntypedUse));
+ }
+
+ m_requiredPhantoms.resize(0);
+ }
</ins><span class="cx">
</span><span class="cx"> BasicBlock* m_block;
</span><span class="cx"> unsigned m_indexInBlock;
</span><span class="cx"> Node* m_currentNode;
</span><span class="cx"> InsertionSet m_insertionSet;
</span><span class="cx"> bool m_profitabilityChanged;
</span><ins>+ Vector<Node*, 3> m_requiredPhantoms;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> bool performFixup(Graph& graph)
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoredfgDFGNodeFlagscpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/dfg/DFGNodeFlags.cpp (161682 => 161683)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/dfg/DFGNodeFlags.cpp        2014-01-10 22:54:16 UTC (rev 161682)
+++ branches/jsCStack/Source/JavaScriptCore/dfg/DFGNodeFlags.cpp        2014-01-10 23:17:57 UTC (rev 161683)
</span><span class="lines">@@ -49,6 +49,9 @@
</span><span class="cx"> case NodeResultInt32:
</span><span class="cx"> out.print(comma, "Int32");
</span><span class="cx"> break;
</span><ins>+ case NodeResultInt52:
+ out.print(comma, "Int52");
+ break;
</ins><span class="cx"> case NodeResultBoolean:
</span><span class="cx"> out.print(comma, "Boolean");
</span><span class="cx"> break;
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoredfgDFGValidatecpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/dfg/DFGValidate.cpp (161682 => 161683)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/dfg/DFGValidate.cpp        2014-01-10 22:54:16 UTC (rev 161682)
+++ branches/jsCStack/Source/JavaScriptCore/dfg/DFGValidate.cpp        2014-01-10 23:17:57 UTC (rev 161683)
</span><span class="lines">@@ -182,6 +182,11 @@
</span><span class="cx"> else
</span><span class="cx"> V_EQUAL((node), node->refCount(), 1);
</span><span class="cx"> }
</span><ins>+
+ for (size_t i = 0 ; i < block->size() - 1; ++i) {
+ Node* node = block->at(i);
+ VALIDATE((node), !node->isTerminal());
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> switch (m_graph.m_form) {
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressexitafterint32todoublejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int32-to-double.js (0 => 161683)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int32-to-double.js         (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int32-to-double.js        2014-01-10 23:17:57 UTC (rev 161683)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+function foo(x, o) {
+ return o.f + x;
+}
+
+noInline(foo);
+
+for (var i = 0; i < 100000; ++i) {
+ var result = foo(42.5, {f:5});
+ if (result != 47.5)
+ throw "Error: bad result: " + result;
+}
+
+var result = foo("42", {f:5});
+if (result != "542")
+ throw "Error: bad result: " + result;
</ins></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressexitafterint52todoublejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int52-to-double.js (0 => 161683)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int52-to-double.js         (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int52-to-double.js        2014-01-10 23:17:57 UTC (rev 161683)
</span><span class="lines">@@ -0,0 +1,16 @@
</span><ins>+function foo(a, b, c) {
+ return a.f + b.f + c.f;
+}
+
+noInline(foo);
+
+for (var i = 0; i < 100000; ++i) {
+ var result = foo({f:2000000000}, {f:2000000000}, {f:0.5});
+ if (result != 4000000000.5)
+ throw "Error: bad result: " + result;
+}
+
+var result = foo({f:2000000000}, {f:2000000000}, {f:"42"});
+if (result != "400000000042")
+ throw "Error: bad result: " + result;
+
</ins></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressexitafterint52tovaluejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int52-to-value.js (0 => 161683)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int52-to-value.js         (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/exit-after-int52-to-value.js        2014-01-10 23:17:57 UTC (rev 161683)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+function foo(a, b, c) {
+ c.f.f = a.f + b.f;
+}
+
+noInline(foo);
+
+var counter = 0;
+function makeWeirdObject() {
+ var result = {};
+ result["blah" + (counter++)] = 42;
+ return result;
+}
+
+for (var i = 0; i < 100000; ++i) {
+ var o = makeWeirdObject();
+ foo({f:2000000000}, {f:2000000000}, {f:o});
+ if (o.f != 4000000000)
+ throw "Error: bad result: " + result;
+}
+
+var thingy;
+Number.prototype.__defineSetter__("f", function(value) { thingy = value; });
+foo({f:2000000000}, {f:2000000000}, {f:42});
+if (thingy != 4000000000)
+ throw "Error: bad result: " + thingy;
</ins></span></pre>
</div>
</div>
</body>
</html>