Skip to content
Permalink
Browse files

[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/878329
Reviewed-by: Michael Stanton <mvstanton@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50813}
  • Loading branch information...
jaro-sevcik authored and Commit Bot committed Jan 22, 2018
1 parent ed93f01 commit b71133245c24149786942793ce3fa1462e9b02d9
Showing with 25 additions and 1 deletion.
  1. +9 −1 src/compiler/dead-code-elimination.cc
  2. +16 −0 test/mjsunit/compiler/regress-803022.js
@@ -139,18 +139,26 @@ Reduction DeadCodeElimination::ReduceLoopOrMerge(Node* node) {
if (live_input_count == 0) {
return Replace(dead());
} else if (live_input_count == 1) {
NodeVector loop_exits(zone_);
// Due to compaction above, the live input is at offset 0.
for (Node* const use : node->uses()) {
if (NodeProperties::IsPhi(use)) {
Replace(use, use->InputAt(0));
} else if (use->opcode() == IrOpcode::kLoopExit &&
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) {
DCHECK_EQ(IrOpcode::kLoop, node->opcode());
Replace(use, dead());
}
}
for (Node* loop_exit : loop_exits) {
loop_exit->ReplaceInput(1, dead());
Revisit(loop_exit);
}
return Replace(node->InputAt(0));
}
DCHECK_LE(2, live_input_count);
@@ -0,0 +1,16 @@
// 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();

0 comments on commit b711332

Please sign in to comment.
You can’t perform that action at this time.