From b53c35a797a37345a1f912ecd51baa651be911c6 Mon Sep 17 00:00:00 2001 From: bmeurer Date: Tue, 26 May 2015 03:47:55 -0700 Subject: [PATCH] [turbofan] Properly kill Terminate nodes when removing loops. BUG=chromium:491578 LOG=n R=jarin@chromium.org Review URL: https://codereview.chromium.org/1161583002 Cr-Commit-Position: refs/heads/master@{#28621} --- src/compiler/control-reducer.cc | 12 ++++++++++-- test/mjsunit/compiler/regress-491578.js | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/mjsunit/compiler/regress-491578.js diff --git a/src/compiler/control-reducer.cc b/src/compiler/control-reducer.cc index 1b8a6b2..a92b4a1 100644 --- a/src/compiler/control-reducer.cc +++ b/src/compiler/control-reducer.cc @@ -439,10 +439,16 @@ class ControlReducerImpl final : public AdvancedReducer { if (live == 0) return dead(); // no remaining inputs. - // Gather phis and effect phis to be edited. + // Gather terminates, phis and effect phis to be edited. NodeVector phis(zone_); + Node* terminate = nullptr; for (Node* const use : node->uses()) { - if (NodeProperties::IsPhi(use)) phis.push_back(use); + if (NodeProperties::IsPhi(use)) { + phis.push_back(use); + } else if (use->opcode() == IrOpcode::kTerminate) { + DCHECK_NULL(terminate); + terminate = use; + } } if (live == 1) { @@ -450,6 +456,8 @@ class ControlReducerImpl final : public AdvancedReducer { for (Node* const phi : phis) { Replace(phi, phi->InputAt(live_index)); } + // The terminate is not needed anymore. + if (terminate) Replace(terminate, dead()); // The merge itself is redundant. return node->InputAt(live_index); } diff --git a/test/mjsunit/compiler/regress-491578.js b/test/mjsunit/compiler/regress-491578.js new file mode 100644 index 0000000..c275704 --- /dev/null +++ b/test/mjsunit/compiler/regress-491578.js @@ -0,0 +1,15 @@ +// 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. + +// Flags: --allow-natives-syntax + +function foo(x) { + if (x === undefined) return; + while (true) { + while (1 || 2) { } + f(); + } +} +%OptimizeFunctionOnNextCall(foo); +foo(); -- 2.7.4