Skip to content

Commit

Permalink
fix: Remove cast for field comparisons in brillig (#2874)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant authored Sep 27, 2023
1 parent b694aab commit 1fc1fdb
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,29 +1034,12 @@ impl<'block> BrilligBlock<'block> {
let binary_type =
type_of_binary_operation(dfg[binary.lhs].get_type(), dfg[binary.rhs].get_type());

let mut left = self.convert_ssa_register_value(binary.lhs, dfg);
let mut right = self.convert_ssa_register_value(binary.rhs, dfg);
let left = self.convert_ssa_register_value(binary.lhs, dfg);
let right = self.convert_ssa_register_value(binary.rhs, dfg);

let brillig_binary_op =
convert_ssa_binary_op_to_brillig_binary_op(binary.operator, &binary_type);

// Some binary operations with fields are issued by the compiler, such as loop comparisons, cast those to the bit size here
// TODO Remove after fixing https://github.com/noir-lang/noir/issues/1979
if let (
BrilligBinaryOp::Integer { bit_size, .. },
Type::Numeric(NumericType::NativeField),
) = (&brillig_binary_op, &binary_type)
{
let new_lhs = self.brillig_context.allocate_register();
let new_rhs = self.brillig_context.allocate_register();

self.brillig_context.cast_instruction(new_lhs, left, *bit_size);
self.brillig_context.cast_instruction(new_rhs, right, *bit_size);

left = new_lhs;
right = new_rhs;
}

self.brillig_context.binary_instruction(left, right, result_register, brillig_binary_op);
}

Expand Down

0 comments on commit 1fc1fdb

Please sign in to comment.