From 47fc3fecfe94e66cff9e6f7a3bfa9c4497288669 Mon Sep 17 00:00:00 2001 From: Tom French Date: Wed, 2 Aug 2023 13:23:59 +0100 Subject: [PATCH] feat: add additional `BinaryOp` simplifictions --- .../src/ssa_refactor/ir/instruction.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs b/crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs index b7a3ea02ae9..6d74a99e002 100644 --- a/crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs +++ b/crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs @@ -733,6 +733,9 @@ impl Binary { let zero = dfg.make_constant(FieldElement::zero(), operand_type); return SimplifyResult::SimplifiedTo(zero); } + if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) { + return SimplifyResult::SimplifiedTo(self.lhs); + } } BinaryOp::Or => { if lhs_is_zero { @@ -741,8 +744,17 @@ impl Binary { if rhs_is_zero { return SimplifyResult::SimplifiedTo(self.lhs); } + if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) { + return SimplifyResult::SimplifiedTo(self.lhs); + } } BinaryOp::Xor => { + if lhs_is_zero { + return SimplifyResult::SimplifiedTo(self.rhs); + } + if rhs_is_zero { + return SimplifyResult::SimplifiedTo(self.lhs); + } if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) { let zero = dfg.make_constant(FieldElement::zero(), Type::bool()); return SimplifyResult::SimplifiedTo(zero);