diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs index ff9b5ea67e..c28e9c6601 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs @@ -9,7 +9,7 @@ use super::{ }; use acvm::acir::{brillig::MemoryAddress, AcirField}; -pub(crate) const MAX_STACK_SIZE: usize = 2048; +pub(crate) const MAX_STACK_SIZE: usize = 32768; pub(crate) const MAX_SCRATCH_SPACE: usize = 64; impl BrilligContext { diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index e30707effe..676bb48c4d 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -630,9 +630,9 @@ impl Instruction { } } Instruction::ArraySet { array, index, value, .. } => { - let array = dfg.get_array_constant(*array); - let index = dfg.get_numeric_constant(*index); - if let (Some((array, element_type)), Some(index)) = (array, index) { + let array_const = dfg.get_array_constant(*array); + let index_const = dfg.get_numeric_constant(*index); + if let (Some((array, element_type)), Some(index)) = (array_const, index_const) { let index = index.try_to_u32().expect("Expected array index to fit in u32") as usize; @@ -641,7 +641,8 @@ impl Instruction { return SimplifiedTo(new_array); } } - None + + try_optimize_array_set_from_previous_get(dfg, *array, *index, *value) } Instruction::Truncate { value, bit_size, max_bit_size } => { if bit_size == max_bit_size { @@ -817,6 +818,27 @@ fn try_optimize_array_get_from_previous_set( SimplifyResult::None } +fn try_optimize_array_set_from_previous_get( + dfg: &DataFlowGraph, + array_id: ValueId, + target_index: ValueId, + target_value: ValueId, +) -> SimplifyResult { + match &dfg[target_value] { + Value::Instruction { instruction, .. } => match &dfg[*instruction] { + Instruction::ArrayGet { array, index } => { + if *array == array_id && *index == target_index { + SimplifyResult::SimplifiedTo(array_id) + } else { + SimplifyResult::None + } + } + _ => SimplifyResult::None, + }, + _ => SimplifyResult::None, + } +} + pub(crate) type ErrorType = HirType; pub(crate) fn error_selector_from_type(typ: &ErrorType) -> ErrorSelector {