diff --git a/src/maglev/maglev-interpreter-frame-state.h b/src/maglev/maglev-interpreter-frame-state.h index 29db80794a..04654df3ed 100644 --- a/src/maglev/maglev-interpreter-frame-state.h +++ b/src/maglev/maglev-interpreter-frame-state.h @@ -113,20 +113,20 @@ class CompactInterpreterFrameState { template void ForEachLocal(const MaglevCompilationUnit& info, Function&& f) const { + int live_reg = 0; for (int register_index : *liveness_) { interpreter::Register reg = interpreter::Register(register_index); - f(live_registers_and_accumulator_[info.parameter_count() + - register_index], + f(live_registers_and_accumulator_[info.parameter_count() + live_reg++], reg); } } template void ForEachLocal(const MaglevCompilationUnit& info, Function&& f) { + int live_reg = 0; for (int register_index : *liveness_) { interpreter::Register reg = interpreter::Register(register_index); - f(live_registers_and_accumulator_[info.parameter_count() + - register_index], + f(live_registers_and_accumulator_[info.parameter_count() + live_reg++], reg); } } @@ -134,7 +134,7 @@ class CompactInterpreterFrameState { template void ForAccumulator(const MaglevCompilationUnit& info, Function&& f) { if (liveness_->AccumulatorIsLive()) { - f(live_registers_and_accumulator_[0]); + f(live_registers_and_accumulator_[SizeFor(info, liveness_) - 1]); } } diff --git a/test/mjsunit/maglev/19.js b/test/mjsunit/maglev/19.js new file mode 100644 index 0000000000..ea2205986c --- /dev/null +++ b/test/mjsunit/maglev/19.js @@ -0,0 +1,25 @@ +// Copyright 2022 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 --maglev + +function f(i) { + var j; + var o; + if (i) { + } else { + if (j) { + } else { + } + } + return o; +} + +%PrepareFunctionForOptimization(f); +f(false, true); + +%OptimizeMaglevOnNextCall(f); +f(false, true); +f(false, true); +f(false, true);