From 52780e65e71ffba0eb636b9fc6eac056c75f55ef Mon Sep 17 00:00:00 2001 From: Malcolm Jestadt Date: Sat, 15 May 2021 06:30:38 -0400 Subject: [PATCH] SPU LLVM: Optimize branching - Detect a pattern where vpmovmskb and a check against the sign bit can be used instead of checking against zero --- rpcs3/Emu/Cell/SPURecompiler.cpp | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index 27b9d7d9d2..e2bb26c7c0 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -8742,6 +8742,29 @@ public: const u32 target = spu_branch_target(m_pos, op.i16); + // Check sign bit instead (optimization) + if (match_vr(op.rt, [&](auto c, auto MP) + { + using VT = typename decltype(MP)::type; + + if (auto [ok, x] = match_expr(c, sext(match]>())); ok) + { + if (target != m_pos + 4) + { + m_block->block_end = m_ir->GetInsertBlock(); + const auto a = get_vr(op.rt); + const auto cond = eval(bitcast(trunc(a)) >= 0); + m_ir->CreateCondBr(cond.value, add_block(target), add_block(m_pos + 4)); + return true; + } + } + + return false; + })) + { + return; + } + if (target != m_pos + 4) { m_block->block_end = m_ir->GetInsertBlock(); @@ -8763,6 +8786,29 @@ public: const u32 target = spu_branch_target(m_pos, op.i16); + // Check sign bit instead (optimization) + if (match_vr(op.rt, [&](auto c, auto MP) + { + using VT = typename decltype(MP)::type; + + if (auto [ok, x] = match_expr(c, sext(match]>())); ok) + { + if (target != m_pos + 4) + { + m_block->block_end = m_ir->GetInsertBlock(); + const auto a = get_vr(op.rt); + const auto cond = eval(bitcast(trunc(a)) < 0); + m_ir->CreateCondBr(cond.value, add_block(target), add_block(m_pos + 4)); + return true; + } + } + + return false; + })) + { + return; + } + if (target != m_pos + 4) { m_block->block_end = m_ir->GetInsertBlock();