diff --git a/compiler/noirc_evaluator/src/ssa.rs b/compiler/noirc_evaluator/src/ssa.rs index ffe3b380c1a..a9525d3e83c 100644 --- a/compiler/noirc_evaluator/src/ssa.rs +++ b/compiler/noirc_evaluator/src/ssa.rs @@ -59,10 +59,12 @@ pub(crate) fn optimize_into_acir( .run_pass(Ssa::remove_bit_shifts, "After Removing Bit Shifts:") // Run mem2reg once more with the flattened CFG to catch any remaining loads/stores .run_pass(Ssa::mem2reg, "After Mem2Reg:") - .run_pass(Ssa::remove_if_else, "After Remove IfElse:") // Run the inlining pass again to handle functions with `InlineType::NoPredicates`. // Before flattening is run, we treat functions marked with the `InlineType::NoPredicates` as an entry point. + // This pass must come immediately following `mem2reg` as the succeeding passes + // may create an SSA which inlining fails to handle. .run_pass(Ssa::inline_functions_with_no_predicates, "After Inlining:") + .run_pass(Ssa::remove_if_else, "After Remove IfElse:") .run_pass(Ssa::fold_constants, "After Constant Folding:") .run_pass(Ssa::remove_enable_side_effects, "After EnableSideEffects removal:") .run_pass(Ssa::fold_constants_using_constraints, "After Constraint Folding:") diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs index c47d594545c..80f6529b7b3 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs @@ -306,7 +306,7 @@ impl<'a> ValueMerger<'a> { // Arbitrarily limit this to looking at at most 10 past ArraySet operations. // If there are more than that, we assume 2 completely separate arrays are being merged. - let max_iters = 1; + let max_iters = 2; let mut seen_then = Vec::with_capacity(max_iters); let mut seen_else = Vec::with_capacity(max_iters); diff --git a/test_programs/execution_success/array_if_cond_simple/Nargo.toml b/test_programs/execution_success/array_if_cond_simple/Nargo.toml new file mode 100644 index 00000000000..b885d22c019 --- /dev/null +++ b/test_programs/execution_success/array_if_cond_simple/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "array_if_cond_simple" +type = "bin" +authors = [""] +compiler_version = ">=0.28.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/array_if_cond_simple/Prover.toml b/test_programs/execution_success/array_if_cond_simple/Prover.toml new file mode 100644 index 00000000000..2825143e8ad --- /dev/null +++ b/test_programs/execution_success/array_if_cond_simple/Prover.toml @@ -0,0 +1,2 @@ +x = true +y = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \ No newline at end of file diff --git a/test_programs/execution_success/array_if_cond_simple/src/main.nr b/test_programs/execution_success/array_if_cond_simple/src/main.nr new file mode 100644 index 00000000000..ee2f762d43c --- /dev/null +++ b/test_programs/execution_success/array_if_cond_simple/src/main.nr @@ -0,0 +1,8 @@ +fn main(x: bool, mut y: [u32; 30]) { + if x { + y[0] = 1; + } + + let z = y[0] + y[1]; + assert(z == 1); +}