LibJS/Bytecode: Stop emitting unnecessary jump at end of for statement

This commit is contained in:
Andreas Kling
2024-05-06 09:36:08 +02:00
parent 69cc64e94c
commit f3d57db774

View File

@@ -850,7 +850,6 @@ Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> ForStatement::gener
Bytecode::BasicBlock* test_block_ptr { nullptr };
Bytecode::BasicBlock* body_block_ptr { nullptr };
Bytecode::BasicBlock* update_block_ptr { nullptr };
Bytecode::BasicBlock* load_result_and_jump_to_end_block_ptr { nullptr };
auto& end_block = generator.make_block();
@@ -901,14 +900,13 @@ Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> ForStatement::gener
generator.emit<Bytecode::Op::Jump>(Bytecode::Label { *test_block_ptr });
if (m_test) {
load_result_and_jump_to_end_block_ptr = &generator.make_block();
generator.switch_to_basic_block(*test_block_ptr);
auto test = TRY(m_test->generate_bytecode(generator)).value();
generator.emit<Bytecode::Op::JumpIf>(
test,
Bytecode::Label { *body_block_ptr },
Bytecode::Label { *load_result_and_jump_to_end_block_ptr });
Bytecode::Label { end_block });
}
if (m_update) {
@@ -933,11 +931,6 @@ Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> ForStatement::gener
}
}
if (load_result_and_jump_to_end_block_ptr) {
generator.switch_to_basic_block(*load_result_and_jump_to_end_block_ptr);
generator.emit<Bytecode::Op::Jump>(Bytecode::Label { end_block });
}
generator.switch_to_basic_block(end_block);
if (has_lexical_environment)