Reviewers: jarin,
Description:
[turbofan] Fix control reducer bug with walking non-control edges during
ConnectNTL phase.
[email protected]
BUG=chromium:469605
LOG=Y
Please review this at https://codereview.chromium.org/1030623003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+64, -31 lines):
M src/compiler/control-reducer.cc
A test/mjsunit/regress/regress-469605.js
Index: src/compiler/control-reducer.cc
diff --git a/src/compiler/control-reducer.cc
b/src/compiler/control-reducer.cc
index
2ada3454b26b149b0d71ade767d9af7e86f6a1e0..0b3aa6ec133428e04378245fa22a32c605abb71c
100644
--- a/src/compiler/control-reducer.cc
+++ b/src/compiler/control-reducer.cc
@@ -106,41 +106,45 @@ class ControlReducerImpl {
marked.Push(start);
marked.SetReachableFromStart(start);
- // We use a stack of (Node, Node::Uses::const_iterator) pairs to avoid
+ // We use a stack of (Node, Node::UseEdges::iterator) pairs to avoid
// O(n^2) traversal.
- typedef std::pair<Node*, Node::Uses::const_iterator> FwIter;
+ typedef std::pair<Node*, Node::UseEdges::iterator> FwIter;
ZoneVector<FwIter> fw_stack(zone_);
- fw_stack.push_back(FwIter(start, start->uses().begin()));
+ fw_stack.push_back(FwIter(start, start->use_edges().begin()));
while (!fw_stack.empty()) {
Node* node = fw_stack.back().first;
TRACE("ControlFw: #%d:%s\n", node->id(), node->op()->mnemonic());
bool pop = true;
- while (fw_stack.back().second != node->uses().end()) {
- Node* succ = *(fw_stack.back().second);
- if (marked.IsOnStack(succ) && !marked.IsReachableFromEnd(succ)) {
- // {succ} is on stack and not reachable from end.
- Node* added = ConnectNTL(succ);
- nodes.push_back(added);
- marked.SetReachableFromEnd(added);
- AddBackwardsReachableNodes(marked, nodes, nodes.size() - 1);
-
- // Reset the use iterators for the entire stack.
- for (size_t i = 0; i < fw_stack.size(); i++) {
- FwIter& iter = fw_stack[i];
- fw_stack[i] = FwIter(iter.first, iter.first->uses().begin());
+ while (fw_stack.back().second != node->use_edges().end()) {
+ Edge edge = *(fw_stack.back().second);
+ if (NodeProperties::IsControlEdge(edge)) {
+ // Only walk control edges.
+ Node* succ = edge.from();
+
+ if (marked.IsOnStack(succ) && !marked.IsReachableFromEnd(succ)) {
+ // {succ} is on stack and not reachable from end.
+ Node* added = ConnectNTL(succ);
+ nodes.push_back(added);
+ marked.SetReachableFromEnd(added);
+ AddBackwardsReachableNodes(marked, nodes, nodes.size() - 1);
+
+ // Reset the use iterators for the entire stack.
+ for (size_t i = 0; i < fw_stack.size(); i++) {
+ FwIter& iter = fw_stack[i];
+ fw_stack[i] = FwIter(iter.first,
iter.first->use_edges().begin());
+ }
+ pop = false; // restart traversing successors of this node.
+ break;
+ }
+ if (!marked.IsReachableFromStart(succ)) {
+ // {succ} is not yet reached from start.
+ marked.Push(succ);
+ marked.SetReachableFromStart(succ);
+ fw_stack.push_back(FwIter(succ, succ->use_edges().begin()));
+ pop = false; // "recurse" into successor control node.
+ break;
}
- pop = false; // restart traversing successors of this node.
- break;
- }
- if (succ->op()->ControlOutputCount() > 0 &&
- !marked.IsReachableFromStart(succ)) {
- // {succ} is a control node and not yet reached from start.
- marked.Push(succ);
- marked.SetReachableFromStart(succ);
- fw_stack.push_back(FwIter(succ, succ->uses().begin()));
- pop = false; // "recurse" into successor control node.
- break;
}
++fw_stack.back().second;
}
@@ -168,6 +172,7 @@ class ControlReducerImpl {
// Connect {loop}, the header of a non-terminating loop, to the end node.
Node* ConnectNTL(Node* loop) {
TRACE("ConnectNTL: #%d:%s\n", loop->id(), loop->op()->mnemonic());
+ DCHECK_EQ(IrOpcode::kLoop, loop->opcode());
Node* always = graph()->NewNode(common_->Always());
// Mark the node as visited so that we can revisit later.
@@ -509,8 +514,8 @@ class ControlReducerImpl {
index++;
}
- TRACE("ReduceMerge: #%d:%s (%d live)\n", node->id(),
node->op()->mnemonic(),
- live);
+ TRACE("ReduceMerge: #%d:%s (%d of %d live)\n", node->id(),
+ node->op()->mnemonic(), live, index);
if (live == 0) return dead(); // no remaining inputs.
@@ -577,7 +582,7 @@ class ControlReducerImpl {
Decision result = DecideCondition(branch->InputAt(0));
if (result == kTrue) {
// fold a true branch by replacing IfTrue with the branch control.
- TRACE("BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
+ TRACE(" BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
branch->op()->mnemonic(), node->id(), node->op()->mnemonic());
return branch->InputAt(1);
}
@@ -591,7 +596,7 @@ class ControlReducerImpl {
Decision result = DecideCondition(branch->InputAt(0));
if (result == kFalse) {
// fold a false branch by replacing IfFalse with the branch control.
- TRACE("BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
+ TRACE(" BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
branch->op()->mnemonic(), node->id(), node->op()->mnemonic());
return branch->InputAt(1);
}
Index: test/mjsunit/regress/regress-469605.js
diff --git a/test/mjsunit/regress/regress-469605.js
b/test/mjsunit/regress/regress-469605.js
new file mode 100644
index
0000000000000000000000000000000000000000..62c2d7d4aa9a7401aaafbe8b4392266b07c33d0c
--- /dev/null
+++ b/test/mjsunit/regress/regress-469605.js
@@ -0,0 +1,28 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var counter1 = 0;
+var counter2 = 0;
+
+function c1() {
+ if (counter1++ == 100) throw "done1";
+}
+
+function c2() {
+ if (counter2++ == 100) throw "done1";
+}
+
+var f = (function() {
+ "use asm";
+ return function f(i) {
+ i = i|0;
+ do {
+ if (i > 0) c1();
+ else c2();
+ } while (true);
+ }
+})();
+
+assertThrows(function() { f(0); });
+assertThrows(function() { f(1); });
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.