Commit acb896b5 authored by Stephan Herhut's avatar Stephan Herhut Committed by Commit Bot

[codegen] Align targets of switch in loops

The blazor benchmark wobbles around by 5% with seemingly unrelated
changes to the generated code. I suspect this is due to moving
target adresses of the switch statement for the interpreter.

Generally, it would make sense to align targets for switch statements
as per general optimization guidelines. To keep code growth in bounds,
this change only enables this for switch statements inside of loops.

Local measurements show an improvement of around 5% for blazor and
hopefully the benchmark will be more stable moving forward.

Bug: chromium:919986 chromium:921477
Change-Id: I69df38f902d4fcc65af9e95a63ca1f7f14e0fa09
Reviewed-on: https://chromium-review.googlesource.com/c/1411637Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58825}
parent 51ad897d
......@@ -629,6 +629,10 @@ static InstructionBlock* InstructionBlockFor(Zone* zone,
for (BasicBlock* predecessor : block->predecessors()) {
instr_block->predecessors().push_back(GetRpo(predecessor));
}
if (block->PredecessorCount() == 1 &&
block->predecessors()[0]->control() == BasicBlock::Control::kSwitch) {
instr_block->set_switch_target(true);
}
return instr_block;
}
......@@ -782,6 +786,9 @@ void InstructionSequence::ComputeAssemblyOrder() {
}
block->set_alignment(header_align);
}
if (block->loop_header().IsValid() && block->IsSwitchTarget()) {
block->set_alignment(true);
}
block->set_ao_number(RpoNumber::FromInt(ao++));
ao_blocks_->push_back(block);
}
......
......@@ -1366,6 +1366,7 @@ class V8_EXPORT_PRIVATE InstructionBlock final
return loop_end_;
}
inline bool IsLoopHeader() const { return loop_end_.IsValid(); }
inline bool IsSwitchTarget() const { return switch_target_; }
inline bool ShouldAlign() const { return alignment_; }
typedef ZoneVector<RpoNumber> Predecessors;
......@@ -1388,6 +1389,8 @@ class V8_EXPORT_PRIVATE InstructionBlock final
void set_alignment(bool val) { alignment_ = val; }
void set_switch_target(bool val) { switch_target_ = val; }
bool needs_frame() const { return needs_frame_; }
void mark_needs_frame() { needs_frame_ = true; }
......@@ -1409,6 +1412,7 @@ class V8_EXPORT_PRIVATE InstructionBlock final
int32_t code_end_ = -1; // end index of arch-specific code.
const bool deferred_ = -1; // Block contains deferred code.
const bool handler_; // Block is a handler entry point.
bool switch_target_ = false;
bool alignment_ = false; // insert alignment before this block
bool needs_frame_ = false;
bool must_construct_frame_ = false;
......
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