constant_propagation_pass: Fold SignExtend{Type}ToLong opcodes if possible

This commit is contained in:
Lioncash 2018-10-05 18:14:56 -04:00 committed by MerryMage
parent 2da2cf9058
commit 43b2eb4688

View file

@ -123,6 +123,15 @@ void FoldSignExtendXToWord(IR::Inst& inst) {
inst.ReplaceUsesWith(IR::Value{static_cast<u32>(value)}); inst.ReplaceUsesWith(IR::Value{static_cast<u32>(value)});
} }
void FoldSignExtendXToLong(IR::Inst& inst) {
if (!inst.AreAllArgsImmediates()) {
return;
}
const s64 value = inst.GetArg(0).GetImmediateAsS64();
inst.ReplaceUsesWith(IR::Value{static_cast<u64>(value)});
}
void FoldZeroExtendXToWord(IR::Inst& inst) { void FoldZeroExtendXToWord(IR::Inst& inst) {
if (!inst.AreAllArgsImmediates()) { if (!inst.AreAllArgsImmediates()) {
return; return;
@ -185,6 +194,11 @@ void ConstantPropagation(IR::Block& block) {
case IR::Opcode::SignExtendHalfToWord: case IR::Opcode::SignExtendHalfToWord:
FoldSignExtendXToWord(inst); FoldSignExtendXToWord(inst);
break; break;
case IR::Opcode::SignExtendByteToLong:
case IR::Opcode::SignExtendHalfToLong:
case IR::Opcode::SignExtendWordToLong:
FoldSignExtendXToLong(inst);
break;
case IR::Opcode::ZeroExtendByteToWord: case IR::Opcode::ZeroExtendByteToWord:
case IR::Opcode::ZeroExtendHalfToWord: case IR::Opcode::ZeroExtendHalfToWord:
FoldZeroExtendXToWord(inst); FoldZeroExtendXToWord(inst);