Skip to content

Commit

Permalink
feat: Add additional BinaryOp simplifications (#2124)
Browse files Browse the repository at this point in the history
feat: add additional `BinaryOp` simplifictions
  • Loading branch information
TomAFrench authored Aug 2, 2023
1 parent f7742ab commit 50b2816
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit 50b2816

Please sign in to comment.