1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:17:35 +00:00

LibJS/Bytecode: Fuse [Not, JumpIf] instructions into JumpIfNot

This commit is contained in:
Andreas Kling 2024-03-03 17:27:53 +01:00
parent 4438ec481c
commit 795149e585
5 changed files with 53 additions and 0 deletions

View file

@ -71,6 +71,7 @@ static void generate_cfg_for_block(BasicBlock const& current_block, PassPipeline
#undef JS_ENUMERATE_FUSABLE_BINARY_OP
case JumpIf:
case JumpIfNot:
case JumpNullish:
case JumpUndefined: {
// FIXME: It would be nice if we could avoid this copy, if we know that the unwind context stays the same in both paths

View file

@ -38,6 +38,20 @@ void Peephole::perform(PassPipelineExecutable& executable)
if (next_instruction.type() == Instruction::Type::JumpIf) {
auto const& jump = static_cast<Op::JumpIf const&>(next_instruction);
if (instruction.type() == Instruction::Type::Not) {
auto const& not_ = static_cast<Op::Not const&>(instruction);
VERIFY(jump.condition() == not_.dst());
new_block->append<Op::JumpIfNot>(
not_.source_record().source_start_offset,
not_.source_record().source_end_offset,
not_.src(),
*jump.true_target(),
*jump.false_target());
++it;
VERIFY(it.at_end());
continue;
}
#define DO_FUSE_JUMP(PreOp, ...) \
if (instruction.type() == Instruction::Type::PreOp) { \
auto const& compare = static_cast<Op::PreOp const&>(instruction); \