Skip to content

Commit 9797576

Browse files
backesV8 LUCI CQ
authored andcommitted
[wasm] Spill all loop inputs before entering loop
This avoids having to load the value back into a register if it was spilled inside of the loop. [email protected] Fixed: chromium:360700873 Change-Id: I24f5deacebc893293e8a3c007e9f070c7fa0ccd2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5797073 Reviewed-by: Jakob Kummerow <[email protected]> Commit-Queue: Clemens Backes <[email protected]> Cr-Commit-Position: refs/heads/main@{#95711}
1 parent 79f3f12 commit 9797576

3 files changed

Lines changed: 12 additions & 31 deletions

File tree

src/wasm/baseline/liftoff-assembler.cc

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -424,29 +424,10 @@ void LiftoffAssembler::DropExceptionValueAtOffset(int offset) {
424424
cache_state_.stack_state.pop_back();
425425
}
426426

427-
void LiftoffAssembler::PrepareLoopArgs(int num) {
428-
for (int i = 0; i < num; ++i) {
429-
VarState& slot = cache_state_.stack_state.end()[-1 - i];
430-
if (slot.is_stack()) continue;
431-
RegClass rc = reg_class_for(slot.kind());
432-
if (slot.is_reg()) {
433-
if (cache_state_.get_use_count(slot.reg()) > 1) {
434-
// If the register is used more than once, we cannot use it for the
435-
// merge. Move it to an unused register instead.
436-
LiftoffRegList pinned;
437-
pinned.set(slot.reg());
438-
LiftoffRegister dst_reg = GetUnusedRegister(rc, pinned);
439-
Move(dst_reg, slot.reg(), slot.kind());
440-
cache_state_.dec_used(slot.reg());
441-
cache_state_.inc_used(dst_reg);
442-
slot.MakeRegister(dst_reg);
443-
}
444-
continue;
445-
}
446-
LiftoffRegister reg = GetUnusedRegister(rc, {});
447-
LoadConstant(reg, slot.constant());
448-
slot.MakeRegister(reg);
449-
cache_state_.inc_used(reg);
427+
void LiftoffAssembler::SpillLoopArgs(int num) {
428+
for (VarState& slot :
429+
base::VectorOf(cache_state_.stack_state.end() - num, num)) {
430+
Spill(&slot);
450431
}
451432
}
452433

@@ -664,14 +645,14 @@ void LiftoffAssembler::Spill(VarState* slot) {
664645
}
665646

666647
void LiftoffAssembler::SpillLocals() {
667-
for (uint32_t i = 0; i < num_locals_; ++i) {
668-
Spill(&cache_state_.stack_state[i]);
648+
for (VarState& local_slot :
649+
base::VectorOf(cache_state_.stack_state.data(), num_locals_)) {
650+
Spill(&local_slot);
669651
}
670652
}
671653

672654
void LiftoffAssembler::SpillAllRegisters() {
673-
for (uint32_t i = 0, e = cache_state_.stack_height(); i < e; ++i) {
674-
auto& slot = cache_state_.stack_state[i];
655+
for (VarState& slot : cache_state_.stack_state) {
675656
if (!slot.is_reg()) continue;
676657
Spill(slot.offset(), slot.reg(), slot.kind());
677658
slot.MakeStack();

src/wasm/baseline/liftoff-assembler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ class LiftoffAssembler : public MacroAssembler {
477477
// the bottom of the stack.
478478
void DropExceptionValueAtOffset(int offset);
479479

480-
// Ensure that the loop inputs are either in a register or spilled to the
481-
// stack, so that we can merge different values on the back-edge.
482-
void PrepareLoopArgs(int num);
480+
// Spill all loop inputs to the stack to free registers and to ensure that we
481+
// can merge different values on the back-edge.
482+
void SpillLoopArgs(int num);
483483

484484
V8_INLINE static int NextSpillOffset(ValueKind kind, int top_spill_offset);
485485
V8_INLINE int NextSpillOffset(ValueKind kind);

src/wasm/baseline/liftoff-compiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ class LiftoffCompiler {
13951395
// pre-analysis of the function.
13961396
__ SpillLocals();
13971397

1398-
__ PrepareLoopArgs(loop->start_merge.arity);
1398+
__ SpillLoopArgs(loop->start_merge.arity);
13991399

14001400
// Loop labels bind at the beginning of the block.
14011401
__ bind(loop->label.get());

0 commit comments

Comments
 (0)