From 133c1a65105c00b6bf6294241ea47c1a683260d6 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Tue, 2 Apr 2024 21:33:07 +0000 Subject: [PATCH 1/2] switch to bit_size from get_value_max_num_bits --- compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs index e491807995b..960874beccd 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs @@ -178,7 +178,7 @@ impl Binary { 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; + 2u128.pow(dfg.type_of_value(non_constant).bit_size()) - 1; if constant > max_possible_value.into() { let zero = dfg.make_constant(FieldElement::zero(), Type::bool()); return SimplifyResult::SimplifiedTo(zero); From a144ef1d2f82795e83abdb513fc0fb91b76e002e Mon Sep 17 00:00:00 2001 From: Tom French Date: Wed, 3 Apr 2024 09:39:52 +0100 Subject: [PATCH 2/2] chore: remove optimisation --- .../src/ssa/ir/instruction/binary.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs index 960874beccd..9099268ace9 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs @@ -171,21 +171,6 @@ impl Binary { return SimplifyResult::SimplifiedTo(one); } - 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. - 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.type_of_value(non_constant).bit_size()) - 1; - if constant > max_possible_value.into() { - let zero = dfg.make_constant(FieldElement::zero(), Type::bool()); - return SimplifyResult::SimplifiedTo(zero); - } - } - } - if operand_type == Type::bool() { // Simplify forms of `(boolean == true)` into `boolean` if lhs_is_one {