diff --git a/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs b/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs index 6cc5239e7a..180f91acf0 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs @@ -189,10 +189,10 @@ impl Context<'_> { let shifted_complement = self.insert_binary(one_complement, BinaryOp::Div, pow); // Convert back to 2-complement representation if operand is negative let lhs_sign_as_int = self.insert_cast(lhs_sign, lhs_typ); - // This shouldn't underflow + // TODO: should this be unchecked? let shifted = self.insert_binary( shifted_complement, - BinaryOp::Sub { unchecked: true }, + BinaryOp::Sub { unchecked: false }, lhs_sign_as_int, ); self.insert_truncate(shifted, bit_size, bit_size + 1) diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs index f54abf4760..23166386dd 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs @@ -523,7 +523,7 @@ impl<'a> FunctionContext<'a> { let not_same = self.builder.insert_not(same_sign); let not_same_sign_field = self.insert_safe_cast(not_same, NumericType::unsigned(bit_size), location); - // TODO: should this be unchecked? + // Unchecked add because adding 1 to half_width can't overflow let positive_maximum_with_offset = self.builder.insert_binary( half_width, BinaryOp::Add { unchecked: true },