diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs index 0f52168a30..81f2f3b1e0 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs @@ -256,6 +256,10 @@ impl Binary { if rhs_is_zero { return SimplifyResult::SimplifiedTo(self.lhs); } + if operand_type == NumericType::bool() && (lhs_is_one || rhs_is_one) { + let one = dfg.make_constant(FieldElement::one(), operand_type); + return SimplifyResult::SimplifiedTo(one); + } if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) { return SimplifyResult::SimplifiedTo(self.lhs); } diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs index 1daa1af790..02be0910a1 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs @@ -480,20 +480,14 @@ fn simplify_slice_push_back( } fn simplify_slice_pop_back( - element_type: Type, + slice_type: Type, arguments: &[ValueId], dfg: &mut DataFlowGraph, block: BasicBlockId, call_stack: CallStack, ) -> SimplifyResult { - let element_types = match element_type.clone() { - Type::Slice(element_types) | Type::Array(element_types, _) => element_types, - _ => { - unreachable!("ICE: Expected slice or array, but got {element_type}"); - } - }; - - let element_count = element_type.element_size(); + let element_types = slice_type.element_types(); + let element_count = element_types.len(); let mut results = VecDeque::with_capacity(element_count + 1); let new_slice_length = update_slice_length(arguments[0], dfg, BinaryOp::Sub, block); @@ -507,14 +501,17 @@ fn simplify_slice_pop_back( flattened_len = update_slice_length(flattened_len, dfg, BinaryOp::Sub, block); // We must pop multiple elements in the case of a slice of tuples - for _ in 0..element_count { + // Iterating through element types in reverse here since we're popping from the end + for element_type in element_types.iter().rev() { let get_last_elem_instr = Instruction::ArrayGet { array: arguments[1], index: flattened_len }; + + let element_type = Some(vec![element_type.clone()]); let get_last_elem = dfg .insert_instruction_and_results( get_last_elem_instr, block, - Some(element_types.to_vec()), + element_type, call_stack.clone(), ) .first(); diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/call/blackbox.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/call/blackbox.rs index c58264dbe8..a5de98cec7 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/call/blackbox.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/call/blackbox.rs @@ -173,7 +173,11 @@ pub(super) fn simplify_msm( var_scalars.push(zero); let result_x = dfg.make_constant(result_x, NumericType::NativeField); let result_y = dfg.make_constant(result_y, NumericType::NativeField); + + // Pushing a bool here is intentional, multi_scalar_mul takes two arguments: + // `points: [(Field, Field, bool); N]` and `scalars: [(Field, Field); N]`. let result_is_infinity = dfg.make_constant(result_is_infinity, NumericType::bool()); + var_points.push(result_x); var_points.push(result_y); var_points.push(result_is_infinity);