From e717961000925cba362957f02ea2bd9fd4dfcb48 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sun, 29 Oct 2023 04:51:25 -0500 Subject: [PATCH] LibJIT: Use `test x, x` instead of `cmp x, 0` in all cases The `test` instruction will have the same result as `cmp` when comparing to zero, so let's always emit that code. This has no effect until the following commit. --- Userland/Libraries/LibJIT/Assembler.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJIT/Assembler.h b/Userland/Libraries/LibJIT/Assembler.h index c8cb12083e..136832ae56 100644 --- a/Userland/Libraries/LibJIT/Assembler.h +++ b/Userland/Libraries/LibJIT/Assembler.h @@ -293,7 +293,9 @@ struct Assembler { void cmp(Operand lhs, Operand rhs) { - if (lhs.type == Operand::Type::Reg && rhs.type == Operand::Type::Reg) { + if (rhs.type == Operand::Type::Imm && rhs.offset_or_immediate == 0) { + test(lhs, lhs); + } else if (lhs.type == Operand::Type::Reg && rhs.type == Operand::Type::Reg) { emit8(0x48 | ((to_underlying(rhs.reg) >= 8) ? 1 << 2 : 0) | ((to_underlying(lhs.reg) >= 8) ? 1 << 0 : 0));