Commit 52e939e9 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[turbofan] Fix accumulator liveness on suspends

SuspendGenerator needs the accumulator to be live so that it can return
it.

Bug: chromium:806723
Change-Id: Iaa88fce96c36876e3e4256324ca650d475480c10
Reviewed-on: https://chromium-review.googlesource.com/975404Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52147}
parent 34022a65
......@@ -103,7 +103,7 @@ void UpdateInLiveness(Bytecode bytecode, BytecodeLivenessState& in_liveness,
in_liveness.MarkRegisterLive(accessor.GetRegisterOperand(0).index());
// Suspend additionally reads and returns the accumulator
DCHECK(Bytecodes::ReadsAccumulator(bytecode));
in_liveness.MarkAccumulatorDead();
in_liveness.MarkAccumulatorLive();
return;
}
if (bytecode == Bytecode::kResumeGenerator) {
......
......@@ -11,6 +11,7 @@
#include "src/interpreter/bytecode-label.h"
#include "src/interpreter/control-flow-builders.h"
#include "src/objects-inl.h"
#include "test/unittests/interpreter/bytecode-utils.h"
#include "test/unittests/test-utils.h"
namespace v8 {
......@@ -452,6 +453,53 @@ TEST_F(BytecodeAnalysisTest, KillingLoopInsideLoop) {
EnsureLivenessMatches(bytecode, expected_liveness);
}
TEST_F(BytecodeAnalysisTest, SuspendPoint) {
interpreter::BytecodeArrayBuilder builder(zone(), 3, 3);
std::vector<std::pair<std::string, std::string>> expected_liveness;
interpreter::Register reg_0(0);
interpreter::Register reg_1(1);
interpreter::Register reg_gen(2);
interpreter::BytecodeJumpTable* gen_jump_table =
builder.AllocateJumpTable(1, 0);
builder.StoreAccumulatorInRegister(reg_gen);
expected_liveness.emplace_back("L..L", "L.LL");
// Note: technically, r0 should be dead here since the resume will write it,
// but in practice the bytecode analysis doesn't bother to special case it,
// since the generator switch is close to the top of the function anyway.
builder.SwitchOnGeneratorState(reg_gen, gen_jump_table);
expected_liveness.emplace_back("L.LL", "L.LL");
builder.StoreAccumulatorInRegister(reg_0);
expected_liveness.emplace_back("..LL", "L.LL");
// Reg 1 is never read, so should be dead.
builder.StoreAccumulatorInRegister(reg_1);
expected_liveness.emplace_back("L.LL", "L.LL");
builder.SuspendGenerator(
reg_gen, interpreter::BytecodeUtils::NewRegisterList(0, 3), 0);
expected_liveness.emplace_back("L.LL", "L.L.");
builder.Bind(gen_jump_table, 0);
builder.ResumeGenerator(reg_gen,
interpreter::BytecodeUtils::NewRegisterList(0, 1));
expected_liveness.emplace_back("L.L.", "L...");
builder.LoadAccumulatorWithRegister(reg_0);
expected_liveness.emplace_back("L...", "...L");
builder.Return();
expected_liveness.emplace_back("...L", "....");
Handle<BytecodeArray> bytecode = builder.ToBytecodeArray(isolate());
EnsureLivenessMatches(bytecode, expected_liveness);
}
} // namespace compiler
} // namespace internal
} // namespace v8
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