Commit b7113324 authored by Jaroslav Sevcik's avatar Jaroslav Sevcik Committed by Commit Bot

[turbofan] Fix dead loop exit removal.

This delays removing dead loop's loop exits after we iterate all uses of
the loop. That way, we avoid mutating the use collection while iterating
it.

Bug: chromium:803022
Change-Id: I17462dd82c3cb78f2f630e5db81d8ccdcc517d83
Reviewed-on: https://chromium-review.googlesource.com/878329Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50813}
parent ed93f014
...@@ -139,18 +139,26 @@ Reduction DeadCodeElimination::ReduceLoopOrMerge(Node* node) { ...@@ -139,18 +139,26 @@ Reduction DeadCodeElimination::ReduceLoopOrMerge(Node* node) {
if (live_input_count == 0) { if (live_input_count == 0) {
return Replace(dead()); return Replace(dead());
} else if (live_input_count == 1) { } else if (live_input_count == 1) {
NodeVector loop_exits(zone_);
// Due to compaction above, the live input is at offset 0. // Due to compaction above, the live input is at offset 0.
for (Node* const use : node->uses()) { for (Node* const use : node->uses()) {
if (NodeProperties::IsPhi(use)) { if (NodeProperties::IsPhi(use)) {
Replace(use, use->InputAt(0)); Replace(use, use->InputAt(0));
} else if (use->opcode() == IrOpcode::kLoopExit && } else if (use->opcode() == IrOpcode::kLoopExit &&
use->InputAt(1) == node) { use->InputAt(1) == node) {
RemoveLoopExit(use); // Remember the loop exits so that we can mark their loop input dead.
// This has to be done after the use list iteration so that we do
// not mutate the use list while it is being iterated.
loop_exits.push_back(use);
} else if (use->opcode() == IrOpcode::kTerminate) { } else if (use->opcode() == IrOpcode::kTerminate) {
DCHECK_EQ(IrOpcode::kLoop, node->opcode()); DCHECK_EQ(IrOpcode::kLoop, node->opcode());
Replace(use, dead()); Replace(use, dead());
} }
} }
for (Node* loop_exit : loop_exits) {
loop_exit->ReplaceInput(1, dead());
Revisit(loop_exit);
}
return Replace(node->InputAt(0)); return Replace(node->InputAt(0));
} }
DCHECK_LE(2, live_input_count); DCHECK_LE(2, live_input_count);
......
// Copyright 2018 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.
// Flags: --allow-natives-syntax
function foo() {
for (var a = 0; a < 2; a++) {
if (a === 1) %OptimizeOsr();
while (0 && 1) {
for (var j = 1; j < 2; j++) { }
}
}
}
foo();
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