constant_propagation_pass: Fold ZeroExtend{Type}ToLong opcodes if possible

These are equivalent to the ZeroExtendXToWord variants, so we can
trivially do this as well.
This commit is contained in:
Lioncash 2018-10-05 18:00:15 -04:00 committed by MerryMage
parent 2274214ff0
commit c42f6ea184

View file

@ -122,6 +122,15 @@ void FoldZeroExtendXToWord(IR::Inst& inst) {
const u64 value = inst.GetArg(0).GetImmediateAsU64(); const u64 value = inst.GetArg(0).GetImmediateAsU64();
inst.ReplaceUsesWith(IR::Value{static_cast<u32>(value)}); inst.ReplaceUsesWith(IR::Value{static_cast<u32>(value)});
} }
void FoldZeroExtendXToLong(IR::Inst& inst) {
if (!inst.AreAllArgsImmediates()) {
return;
}
const u64 value = inst.GetArg(0).GetImmediateAsU64();
inst.ReplaceUsesWith(IR::Value{value});
}
} // Anonymous namespace } // Anonymous namespace
void ConstantPropagation(IR::Block& block) { void ConstantPropagation(IR::Block& block) {
@ -167,6 +176,11 @@ void ConstantPropagation(IR::Block& block) {
case IR::Opcode::ZeroExtendHalfToWord: case IR::Opcode::ZeroExtendHalfToWord:
FoldZeroExtendXToWord(inst); FoldZeroExtendXToWord(inst);
break; break;
case IR::Opcode::ZeroExtendByteToLong:
case IR::Opcode::ZeroExtendHalfToLong:
case IR::Opcode::ZeroExtendWordToLong:
FoldZeroExtendXToLong(inst);
break;
default: default:
break; break;
} }