From d51a83d26565b58960bb526215d7b300d7b6675e Mon Sep 17 00:00:00 2001 From: MerryMage Date: Wed, 22 Apr 2020 00:20:38 +0100 Subject: [PATCH] constant_propagation_pass: Fold IsZero --- src/ir_opt/constant_propagation_pass.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ir_opt/constant_propagation_pass.cpp b/src/ir_opt/constant_propagation_pass.cpp index cf7592cc..02e8b104 100644 --- a/src/ir_opt/constant_propagation_pass.cpp +++ b/src/ir_opt/constant_propagation_pass.cpp @@ -337,6 +337,16 @@ void ConstantPropagation(IR::Block& block) { case Op::MostSignificantBit: FoldMostSignificantBit(inst); break; + case Op::IsZero32: + if (inst.AreAllArgsImmediates()) { + inst.ReplaceUsesWith(IR::Value{inst.GetArg(0).GetU32() == 0}); + } + break; + case Op::IsZero64: + if (inst.AreAllArgsImmediates()) { + inst.ReplaceUsesWith(IR::Value{inst.GetArg(0).GetU64() == 0}); + } + break; case Op::LogicalShiftLeft32: if (FoldShifts(inst)) { ReplaceUsesWith(inst, true, Safe::LogicalShiftLeft(inst.GetArg(0).GetU32(), inst.GetArg(1).GetU8()));