Commit 3244a665 authored by Ben L. Titzer's avatar Ben L. Titzer

[turbofan] Fix corner case in loop analysis.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/852783002

Cr-Commit-Position: refs/heads/master@{#26063}
parent b301b85b
...@@ -152,18 +152,22 @@ class LoopFinderImpl { ...@@ -152,18 +152,22 @@ class LoopFinderImpl {
queued_.Set(node, false); queued_.Set(node, false);
// Setup loop headers first. // Setup loop headers first.
NodeInfo& ni = info(node);
if (node->opcode() == IrOpcode::kLoop) { if (node->opcode() == IrOpcode::kLoop) {
// found the loop node first. // found the loop node first.
CreateLoopInfo(node); CreateLoopInfo(node, ni);
} else if (node->opcode() == IrOpcode::kPhi || } else if (node->opcode() == IrOpcode::kPhi ||
node->opcode() == IrOpcode::kEffectPhi) { node->opcode() == IrOpcode::kEffectPhi) {
// found a phi first. // found a phi first.
Node* merge = node->InputAt(node->InputCount() - 1); Node* merge = node->InputAt(node->InputCount() - 1);
if (merge->opcode() == IrOpcode::kLoop) CreateLoopInfo(merge); if (merge->opcode() == IrOpcode::kLoop) {
NodeInfo& mi = info(merge);
CreateLoopInfo(merge, mi);
ni.MarkBackward(mi.loop_mark);
}
} }
// Propagate reachability marks backwards from this node. // Propagate reachability marks backwards from this node.
NodeInfo& ni = info(node);
if (ni.IsLoopHeader()) { if (ni.IsLoopHeader()) {
// Handle edges from loop header nodes specially. // Handle edges from loop header nodes specially.
for (int i = 0; i < node->InputCount(); i++) { for (int i = 0; i < node->InputCount(); i++) {
...@@ -186,8 +190,7 @@ class LoopFinderImpl { ...@@ -186,8 +190,7 @@ class LoopFinderImpl {
} }
// Make a new loop header for the given node. // Make a new loop header for the given node.
void CreateLoopInfo(Node* node) { void CreateLoopInfo(Node* node, NodeInfo& ni) {
NodeInfo& ni = info(node);
if (ni.IsLoopHeader()) return; // loop already set up. if (ni.IsLoopHeader()) return; // loop already set up.
loops_found_++; loops_found_++;
...@@ -197,7 +200,6 @@ class LoopFinderImpl { ...@@ -197,7 +200,6 @@ class LoopFinderImpl {
loops_.push_back({node, nullptr, nullptr, nullptr}); loops_.push_back({node, nullptr, nullptr, nullptr});
loop_tree_->NewLoop(); loop_tree_->NewLoop();
LoopMarks loop_mark = kVisited | (1 << loop_num); LoopMarks loop_mark = kVisited | (1 << loop_num);
ni.node = node;
ni.loop_mark = loop_mark; ni.loop_mark = loop_mark;
// Setup loop mark for phis attached to loop header. // Setup loop mark for phis attached to loop header.
......
...@@ -262,6 +262,23 @@ TEST(LaLoop1) { ...@@ -262,6 +262,23 @@ TEST(LaLoop1) {
} }
TEST(LaLoop1phi) {
// One loop with a simple phi.
LoopFinderTester t;
While w(t, t.p0);
Node* phi =
t.graph.NewNode(t.common.Phi(kMachAnyTagged, 2), t.zero, t.one, w.loop);
t.Return(phi, t.start, w.exit);
Node* chain[] = {w.loop};
t.CheckNestedLoops(chain, 1);
Node* header[] = {w.loop, phi};
Node* body[] = {w.branch, w.if_true};
t.CheckLoop(header, 2, body, 2);
}
TEST(LaLoop1c) { TEST(LaLoop1c) {
// One loop with a counter. // One loop with a counter.
LoopFinderTester t; LoopFinderTester t;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment