Commit ef1dfcad authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[maglev] Don't allocate dead phis

Avoid allocating dead (zero live range) phis, or their inputs. We should
figure out a way to remove them from the graph entirely, e.g. in a
separate DCE phase, but for now the easiest thing to do is to skip over
them.

Note that we can't eliminate them as part of the current node processing
pass, since that's the thing that records live ranges in the first
place.

Bug: v8:7700
Change-Id: I3e7f1f2214100def9ccc2b3f008852d5d69f548f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3784985Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81954}
parent 4d07e0bf
......@@ -361,6 +361,20 @@ class MaglevCodeGeneratingNodeProcessor {
if (target->has_phi()) {
Phi::List* phis = target->phis();
for (Phi* phi : *phis) {
// Ignore dead phis.
// TODO(leszeks): We should remove dead phis entirely and turn this into
// a DCHECK.
if (!phi->has_valid_live_range()) {
if (FLAG_code_comments) {
std::stringstream ss;
ss << "-- * "
<< phi->input(state.block()->predecessor_id()).operand() << " → "
<< target << " (n" << graph_labeller()->NodeId(phi)
<< ") [DEAD]";
__ RecordComment(ss.str());
}
continue;
}
Input& input = phi->input(state.block()->predecessor_id());
ValueNode* node = input.node();
compiler::InstructionOperand source = input.operand();
......
......@@ -302,11 +302,19 @@ void StraightForwardRegisterAllocator::AllocateRegisters() {
// Firstly, make the phi live, and try to assign it to an input
// location.
for (Phi* phi : *block->phis()) {
// Ignore dead phis.
// TODO(leszeks): We should remove dead phis entirely and turn this into
// a DCHECK.
if (!phi->has_valid_live_range()) continue;
phi->SetNoSpillOrHint();
TryAllocateToInput(phi);
}
// Secondly try to assign the phi to a free register.
for (Phi* phi : *block->phis()) {
// Ignore dead phis.
// TODO(leszeks): We should remove dead phis entirely and turn this into
// a DCHECK.
if (!phi->has_valid_live_range()) continue;
if (phi->result().operand().IsAllocated()) continue;
// We assume that Phis are always untagged, and so are always allocated
// in a general register.
......@@ -324,6 +332,10 @@ void StraightForwardRegisterAllocator::AllocateRegisters() {
}
// Finally just use a stack slot.
for (Phi* phi : *block->phis()) {
// Ignore dead phis.
// TODO(leszeks): We should remove dead phis entirely and turn this into
// a DCHECK.
if (!phi->has_valid_live_range()) continue;
if (phi->result().operand().IsAllocated()) continue;
AllocateSpillSlot(phi);
// TODO(verwaest): Will this be used at all?
......@@ -647,6 +659,11 @@ void StraightForwardRegisterAllocator::InitializeBranchTargetPhis(
// state as the phi input.
Phi::List* phis = target->phis();
for (Phi* phi : *phis) {
// Ignore dead phis.
// TODO(leszeks): We should remove dead phis entirely and turn this into a
// DCHECK.
if (!phi->has_valid_live_range()) continue;
Input& input = phi->input(predecessor_id);
input.InjectLocation(input.node()->allocation());
}
......@@ -1025,6 +1042,10 @@ void StraightForwardRegisterAllocator::VerifyRegisterState() {
for (BasicBlock* block : *graph_) {
if (block->has_phi()) {
for (Phi* phi : *block->phis()) {
// Ignore dead phis.
// TODO(leszeks): We should remove dead phis entirely and turn this into
// a DCHECK.
if (!phi->has_valid_live_range()) continue;
ValidateValueNode(phi);
}
}
......
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