From 4ecb06c901effffa28850f74a9ed39e66f3a9b6b Mon Sep 17 00:00:00 2001 From: Whatcookie Date: Fri, 28 Jul 2023 03:26:40 -0400 Subject: [PATCH] SPU LLVM: Optimize common SFI+ROTQMBY pattern --- rpcs3/Emu/Cell/SPURecompiler.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index 6df6380485..1dd9acab29 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -7788,19 +7788,27 @@ public: void ROTQMBY(spu_opcode_t op) { const auto a = get_vr(op.ra); - const auto b = get_vr(op.rb); + const auto b = get_vr(op.rb); + + auto minusb = eval(-b); + if (auto [ok, x] = match_expr(b, -match()); ok) + { + minusb = eval(x); + } + + const auto minusbx = bitcast(minusb); // Data with swapped endian from a load instruction if (auto [ok, as] = match_expr(a, byteswap(match())); ok) { const auto sc = build(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); - const auto sh = sc - (-splat_scalar(b) & 0x1f); + const auto sh = sc - (splat_scalar(minusbx) & 0x1f); set_vr(op.rt, pshufb(as, sh)); return; } const auto sc = build(112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127); - const auto sh = sc + (-splat_scalar(b) & 0x1f); + const auto sh = sc + (splat_scalar(minusbx) & 0x1f); set_vr(op.rt, pshufb(a, sh)); }