Skip to content

Commit

Permalink
Update compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs
Browse files Browse the repository at this point in the history
Co-authored-by: jfecher <jake@aztecprotocol.com>
  • Loading branch information
TomAFrench and jfecher authored Apr 2, 2024
1 parent 0927c65 commit 37345f4
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,15 @@ impl Binary {
if operand_type.is_unsigned() {
// If we're comparing a variable against a constant value which lies outside of the range of
// values which the variable's type can take, we can assume that the equality will be false.
match (lhs, rhs) {
(Some(lhs), None) => {
let max_possible_value =
2u128.pow(dfg.get_value_max_num_bits(self.rhs)) - 1;
if lhs > max_possible_value.into() {
let zero = dfg.make_constant(FieldElement::zero(), Type::bool());
return SimplifyResult::SimplifiedTo(zero);
}
}

(None, Some(rhs)) => {
let max_possible_value =
2u128.pow(dfg.get_value_max_num_bits(self.lhs)) - 1;
if rhs > max_possible_value.into() {
let zero = dfg.make_constant(FieldElement::zero(), Type::bool());
return SimplifyResult::SimplifiedTo(zero);
}
}

(None, None) => (),
(Some(_), Some(_)) => {
unreachable!("Constant binary instructions should be handled above")
let constant = lhs.or(rhs);
let non_constant = if lhs.is_some() { self.rhs } else { self.lhs };

if let Some(constant) = constant {
let max_possible_value =
2u128.pow(dfg.get_value_max_num_bits(non_constant)) - 1;
if constant > max_possible_value.into() {
let zero = dfg.make_constant(FieldElement::zero(), Type::bool());
return SimplifyResult::SimplifiedTo(zero);
}
}
}
Expand Down

0 comments on commit 37345f4

Please sign in to comment.