From 592ba31e224c062fe558dad21d2f605196df0b31 Mon Sep 17 00:00:00 2001 From: Bram Speeckaert Date: Tue, 1 Nov 2022 11:51:57 +0100 Subject: [PATCH] JitArm64: cmp - Optimize a == 0 case By explicitly handling this, we can avoid materializing zero in a register and generate more efficient code altogether. Before: 0x52800016 mov w22, #0x0 0xb94093b5 ldr w21, [x29, #0x90] 0x93407ed7 sxtw x23, w22 0x93407eb9 sxtw x25, w21 0xcb1902f9 sub x25, x23, x25 After: 0xb94093b7 ldr w23, [x29, #0x90] 0x4b1703f9 neg w25, w23 0x93407f39 sxtw x25, w25 --- Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index 2b46e80e70..2166a1427d 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -579,6 +579,11 @@ void JitArm64::cmp(UGeckoInstruction inst) s64 B = static_cast(gpr.GetImm(b)); MOVI2R(CR, A - B); } + else if (gpr.IsImm(a) && !gpr.GetImm(a)) + { + NEG(EncodeRegTo32(CR), gpr.R(b)); + SXTW(CR, EncodeRegTo32(CR)); + } else if (gpr.IsImm(b) && !gpr.GetImm(b)) { SXTW(CR, gpr.R(a));