CPU/Recompiler: Optimize beq zero, zero, addr to unconditional branch
Seems to exist in some BIOS code. Credit to @Dillonb for the idea.
This commit is contained in:
parent
55f0915534
commit
f071497be5
|
@ -1736,11 +1736,20 @@ bool CodeGenerator::Compile_Branch(const CodeBlockInstruction& cbi)
|
||||||
// npc = pc + (sext(imm) << 2)
|
// npc = pc + (sext(imm) << 2)
|
||||||
Value branch_target = CalculatePC(cbi.instruction.i.imm_sext32() << 2);
|
Value branch_target = CalculatePC(cbi.instruction.i.imm_sext32() << 2);
|
||||||
|
|
||||||
// branch <- rs op rt
|
// beq zero, zero, addr -> unconditional branch
|
||||||
Value lhs = m_register_cache.ReadGuestRegister(cbi.instruction.i.rs, true, true);
|
if (cbi.instruction.op == InstructionOp::beq && cbi.instruction.i.rs == Reg::zero &&
|
||||||
Value rhs = m_register_cache.ReadGuestRegister(cbi.instruction.i.rt);
|
cbi.instruction.i.rt == Reg::zero)
|
||||||
const Condition condition = (cbi.instruction.op == InstructionOp::beq) ? Condition::Equal : Condition::NotEqual;
|
{
|
||||||
DoBranch(condition, lhs, rhs, Reg::count, std::move(branch_target));
|
DoBranch(Condition::Always, Value(), Value(), Reg::count, std::move(branch_target));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// branch <- rs op rt
|
||||||
|
Value lhs = m_register_cache.ReadGuestRegister(cbi.instruction.i.rs, true, true);
|
||||||
|
Value rhs = m_register_cache.ReadGuestRegister(cbi.instruction.i.rt);
|
||||||
|
const Condition condition = (cbi.instruction.op == InstructionOp::beq) ? Condition::Equal : Condition::NotEqual;
|
||||||
|
DoBranch(condition, lhs, rhs, Reg::count, std::move(branch_target));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue