From c42f6ea184f31f43dd15db76c9f3577d8a1ad97c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Oct 2018 18:00:15 -0400 Subject: [PATCH] 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. --- src/ir_opt/constant_propagation_pass.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ir_opt/constant_propagation_pass.cpp b/src/ir_opt/constant_propagation_pass.cpp index 6cab7fc4..037f522e 100644 --- a/src/ir_opt/constant_propagation_pass.cpp +++ b/src/ir_opt/constant_propagation_pass.cpp @@ -122,6 +122,15 @@ void FoldZeroExtendXToWord(IR::Inst& inst) { const u64 value = inst.GetArg(0).GetImmediateAsU64(); inst.ReplaceUsesWith(IR::Value{static_cast(value)}); } + +void FoldZeroExtendXToLong(IR::Inst& inst) { + if (!inst.AreAllArgsImmediates()) { + return; + } + + const u64 value = inst.GetArg(0).GetImmediateAsU64(); + inst.ReplaceUsesWith(IR::Value{value}); +} } // Anonymous namespace void ConstantPropagation(IR::Block& block) { @@ -167,6 +176,11 @@ void ConstantPropagation(IR::Block& block) { case IR::Opcode::ZeroExtendHalfToWord: FoldZeroExtendXToWord(inst); break; + case IR::Opcode::ZeroExtendByteToLong: + case IR::Opcode::ZeroExtendHalfToLong: + case IR::Opcode::ZeroExtendWordToLong: + FoldZeroExtendXToLong(inst); + break; default: break; }