constant_propagation_pass: Fold SignExtend{Type}ToWord opcodes if possible

This commit is contained in:
Lioncash 2018-10-05 18:08:16 -04:00 committed by MerryMage
parent c42f6ea184
commit 2da2cf9058

View file

@ -114,6 +114,15 @@ void FoldOR(IR::Inst& inst, bool is_32_bit) {
} }
} }
void FoldSignExtendXToWord(IR::Inst& inst) {
if (!inst.AreAllArgsImmediates()) {
return;
}
const s64 value = inst.GetArg(0).GetImmediateAsS64();
inst.ReplaceUsesWith(IR::Value{static_cast<u32>(value)});
}
void FoldZeroExtendXToWord(IR::Inst& inst) { void FoldZeroExtendXToWord(IR::Inst& inst) {
if (!inst.AreAllArgsImmediates()) { if (!inst.AreAllArgsImmediates()) {
return; return;
@ -172,6 +181,10 @@ void ConstantPropagation(IR::Block& block) {
case IR::Opcode::Not64: case IR::Opcode::Not64:
FoldNOT(inst, opcode == IR::Opcode::Not32); FoldNOT(inst, opcode == IR::Opcode::Not32);
break; break;
case IR::Opcode::SignExtendByteToWord:
case IR::Opcode::SignExtendHalfToWord:
FoldSignExtendXToWord(inst);
break;
case IR::Opcode::ZeroExtendByteToWord: case IR::Opcode::ZeroExtendByteToWord:
case IR::Opcode::ZeroExtendHalfToWord: case IR::Opcode::ZeroExtendHalfToWord:
FoldZeroExtendXToWord(inst); FoldZeroExtendXToWord(inst);