LibJS/Bytecode: Avoid unnecessary copy of call expression callee

If the callee is already a temporary register, we don't need to copy it
to *another* temporary before evaluating arguments. None of the
arguments will clobber the existing temporary anyway.
This commit is contained in:
Andreas Kling 2024-05-09 19:52:38 +02:00 committed by Alexander Kalenik
commit 96511a7d19
Notes: sideshowbarker 2024-07-16 23:44:30 +09:00

View file

@ -1652,9 +1652,16 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> CallExpression::generat
original_callee = TRY(m_callee->generate_bytecode(generator)).value();
}
// NOTE: We copy the callee to a new register to avoid overwriting it while evaluating arguments.
auto callee = generator.allocate_register();
generator.emit<Bytecode::Op::Mov>(callee, *original_callee);
// NOTE: If the callee isn't already a temporary, we copy it to a new register
// to avoid overwriting it while evaluating arguments.
auto callee = [&]() -> ScopedOperand {
if (!original_callee->operand().is_register()) {
auto callee = generator.allocate_register();
generator.emit<Bytecode::Op::Mov>(callee, *original_callee);
return callee;
}
return *original_callee;
}();
Bytecode::Op::CallType call_type;
if (is<NewExpression>(*this)) {