Commit e8c8ba9a authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[TurboProp] Add tests for spills of phis before gap move.

Adds unittests that test the fast register allocator correctly deals
with spills of Phi's between their definition and a predecessor block's
gap move to populate the Phi.

BUG=v8:9684

Change-Id: I17263058d5ac29088895ad3de7b3131315ec8fae
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2299371
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69141}
parent 29f1ad28
......@@ -1812,12 +1812,12 @@ void MidTierRegisterAllocator::AllocateRegisters(
double_reg_allocator().EndInstruction();
}
AllocatePhis(block);
// TODO(rmcilroy): Add support for cross-block allocations.
general_reg_allocator().SpillAllRegisters();
double_reg_allocator().SpillAllRegisters();
AllocatePhis(block);
general_reg_allocator().EndBlock(block);
double_reg_allocator().EndBlock(block);
}
......
......@@ -119,11 +119,11 @@ Instruction* InstructionSequenceTest::EndBlock(BlockCompletion completion) {
case kBlockEnd:
break;
case kFallThrough:
result = EmitJump();
result = EmitJump(completion.op_);
break;
case kJump:
CHECK(!block_returns_);
result = EmitJump();
result = EmitJump(completion.op_);
break;
case kBranch:
CHECK(!block_returns_);
......@@ -295,8 +295,8 @@ Instruction* InstructionSequenceTest::EmitFallThrough() {
return AddInstruction(instruction);
}
Instruction* InstructionSequenceTest::EmitJump() {
InstructionOperand inputs[1]{ConvertInputOp(Imm())};
Instruction* InstructionSequenceTest::EmitJump(TestOperand input_op) {
InstructionOperand inputs[1]{ConvertInputOp(input_op)};
auto instruction = NewInstruction(kArchJmp, 0, nullptr, 1, inputs);
return AddInstruction(instruction);
}
......
......@@ -124,12 +124,15 @@ class InstructionSequenceTest : public TestWithIsolateAndZone {
};
static BlockCompletion FallThrough() {
BlockCompletion completion = {kFallThrough, TestOperand(), 1, kNoValue};
BlockCompletion completion = {kFallThrough, TestOperand(kImmediate, 0), 1,
kNoValue};
return completion;
}
static BlockCompletion Jump(int offset) {
BlockCompletion completion = {kJump, TestOperand(), offset, kNoValue};
static BlockCompletion Jump(int offset,
TestOperand operand = TestOperand(kImmediate,
0)) {
BlockCompletion completion = {kJump, operand, offset, kNoValue};
return completion;
}
......@@ -223,7 +226,7 @@ class InstructionSequenceTest : public TestWithIsolateAndZone {
Instruction* EmitBranch(TestOperand input_op);
Instruction* EmitFallThrough();
Instruction* EmitJump();
Instruction* EmitJump(TestOperand input_op);
Instruction* NewInstruction(InstructionCode code, size_t outputs_size,
InstructionOperand* outputs,
size_t inputs_size = 0,
......
......@@ -269,6 +269,75 @@ TEST_F(MidTierRegisterAllocatorTest, SpillPhi) {
Allocate();
}
TEST_F(MidTierRegisterAllocatorTest, SpillPhiDueToConstrainedJump) {
StartBlock();
auto p_0 = Parameter(Reg(1));
EndBlock(Branch(Imm(), 1, 2));
StartBlock();
EndBlock(Branch(Imm(), 2, 4));
StartBlock();
EndBlock(Branch(Imm(), 2, 4));
StartBlock();
auto l_0 = Define(Reg());
EndBlock(Jump(4, Reg(p_0, 1)));
StartBlock();
auto l_1 = Define(Reg());
EndBlock(Jump(3, Reg(p_0)));
StartBlock();
auto l_2 = Define(Reg());
EndBlock(Jump(2, Reg(p_0, 1)));
StartBlock();
auto l_3 = Define(Reg());
EndBlock(Jump(1, Reg(p_0)));
StartBlock();
auto phi = Phi(l_0, l_1, l_2, l_3);
Return(Reg(phi, 1));
EndBlock();
Allocate();
}
TEST_F(MidTierRegisterAllocatorTest, SpillPhiDueToRegisterPressure) {
VReg left[Register::kNumRegisters];
VReg right[Register::kNumRegisters];
VReg phis[Register::kNumRegisters];
StartBlock();
auto p_0 = Parameter(Reg(1));
EndBlock(Branch(Imm(), 1, 2));
StartBlock();
for (int i = 0; i < Register::kNumRegisters; ++i) {
left[i] = Define(Reg());
}
EndBlock(Jump(2, Reg(p_0)));
StartBlock();
for (int i = 0; i < Register::kNumRegisters; ++i) {
right[i] = Define(Reg());
}
EndBlock(Jump(1, Reg(p_0)));
StartBlock();
for (int i = 0; i < Register::kNumRegisters; ++i) {
phis[i] = Phi(left[i], right[i]);
}
for (int i = 0; i < Register::kNumRegisters; ++i) {
EmitI(Reg(phis[i]));
}
Return(Reg(phis[0], 1));
EndBlock();
Allocate();
}
TEST_F(MidTierRegisterAllocatorTest, MoveLotsOfConstants) {
FLAG_trace_turbo = true;
StartBlock();
......
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