fix(ssa): Swap Brillig index shift and DIE in minimal pipeline#8946
fix(ssa): Swap Brillig index shift and DIE in minimal pipeline#8946
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 37b8ca0 | Previous: 51f6b7c | Ratio |
|---|---|---|---|
rollup-merge |
0.004 s |
0.003 s |
1.33 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
It is not. Global values are declared by users. We just also use them within the compiler for sharing constants across functions. We may want to move to only sharing array constants in globals and always inlining simple numeric constants, but that would be a separate experiment. |
…-brillig-index-global-const
I didn't mean it was wrong to use it, or that it's artificially introduced into the globals, just wanted to say that it seems a bit random if e.g. a single array item ends up surviving from the globals only because a shift ends up matching its value. In other words, it's not like we piggy back on a global that has its use on its own in the current SSA, but this way we save an extra slot, but rather this is the only thing that keeps it being used. There is no mechanism to seek opportunities for sharing, by elevating constants into the global space. Anyway, thanks for confirming that it works as intended! |
Ah I see. We do in fact have a mechanism for elevating local constants to global constants, it just occurs after SSA gen and as part of Brillig gen. You can look in |
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(LSP): suggest generic type methods (noir-lang/noir#8948) fix: Fix if/match tracking in last uses pass (noir-lang/noir#8935) fix(ssa): Swap Brillig index shift and DIE in minimal pipeline (noir-lang/noir#8946) fix: when macro parse error happens, discard warnings; also preserve unquoted token locations (noir-lang/noir#8944) chore: disable noncritical workflow steps which fail on external prs (noir-lang/noir#8939) chore(test): Add `--minimal-ssa` to integration tests (noir-lang/noir#8938) fix(noirc_evaluator): U128 Binary::And simplification (noir-lang/noir#8940) chore: Improve access to data required to extract Noir (noir-lang/noir#8793) chore: bump external pinned commits (noir-lang/noir#8920) chore(fuzz): Compare print output on failed programs (noir-lang/noir#8921) chore(fuzz): Display nightly fuzz status badge (noir-lang/noir#8932) fix(fuzz): Consider values returned from Brillig to ACIR as dynamic (noir-lang/noir#8931) fix(fuzz): Fix env var name in fuzzing workflow (noir-lang/noir#8929) chore(fuzz): Add nightly fuzz workflow with 5 minute budget (noir-lang/noir#8925) fix(mem2reg): Keep last store for a used nested array (noir-lang/noir#8917) chore(fuzz): Increase the number of deterministic test cases (noir-lang/noir#8872) fix: Create calls to `apply` before function values are changed to fields in defunctionalize (noir-lang/noir#8916) chore: Add various regression tests for mutable references (noir-lang/noir#8915) fix: handle return_data in the interpreter SSA CLI (noir-lang/noir#8914) feat(fuzz): Generate references in the AST fuzzer (noir-lang/noir#8728) fix(fuzz): Use an inline block to circumvent negation with overflow (noir-lang/noir#8911) fix: Inline global arrays with functions at their call site (noir-lang/noir#8905) chore: Casting ACIR vs Brillig regression tests (noir-lang/noir#8903) fix(mem2reg): Keep last store for reference in array used only in an array get (noir-lang/noir#8877) fix: more SSA interpreter fixes (noir-lang/noir#8904) chore: Ban dynamic array indices with reference elements (noir-lang/noir#8888) chore(ssa_fuzzer): Add SSA validation to the SSA fuzzer (noir-lang/noir#8901) chore(fuzz): More metamorphic rules (noir-lang/noir#8857) fix: catch unbound type variables during frontend compilation (noir-lang/noir#8686) fix: preserve functions which are used in `array_set` instructions (noir-lang/noir#8891) fix: assorted SSA interpreter fixes (noir-lang/noir#8893) fix(ssa): Signed cast simplification (noir-lang/noir#8862) feat: simplify apply function cfg immediately (noir-lang/noir#8895) fix: do not hoist control dependent cast (noir-lang/noir#8886) fix(licm): Account for negative bounds when checking whether a loop executes (noir-lang/noir#8889) chore: Release Noir(1.0.0-beta.7) (noir-lang/noir#8520) chore: test noir-ecdsa library in CI (noir-lang/noir#8859) chore: Incorrect clippy warning blocking PRs (noir-lang/noir#8861) END_COMMIT_OVERRIDE --------- Co-authored-by: AztecBot <tech@aztecprotocol.com> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(LSP): suggest generic type methods (noir-lang/noir#8948) fix: Fix if/match tracking in last uses pass (noir-lang/noir#8935) fix(ssa): Swap Brillig index shift and DIE in minimal pipeline (noir-lang/noir#8946) fix: when macro parse error happens, discard warnings; also preserve unquoted token locations (noir-lang/noir#8944) chore: disable noncritical workflow steps which fail on external prs (noir-lang/noir#8939) chore(test): Add `--minimal-ssa` to integration tests (noir-lang/noir#8938) fix(noirc_evaluator): U128 Binary::And simplification (noir-lang/noir#8940) chore: Improve access to data required to extract Noir (noir-lang/noir#8793) chore: bump external pinned commits (noir-lang/noir#8920) chore(fuzz): Compare print output on failed programs (noir-lang/noir#8921) chore(fuzz): Display nightly fuzz status badge (noir-lang/noir#8932) fix(fuzz): Consider values returned from Brillig to ACIR as dynamic (noir-lang/noir#8931) fix(fuzz): Fix env var name in fuzzing workflow (noir-lang/noir#8929) chore(fuzz): Add nightly fuzz workflow with 5 minute budget (noir-lang/noir#8925) fix(mem2reg): Keep last store for a used nested array (noir-lang/noir#8917) chore(fuzz): Increase the number of deterministic test cases (noir-lang/noir#8872) fix: Create calls to `apply` before function values are changed to fields in defunctionalize (noir-lang/noir#8916) chore: Add various regression tests for mutable references (noir-lang/noir#8915) fix: handle return_data in the interpreter SSA CLI (noir-lang/noir#8914) feat(fuzz): Generate references in the AST fuzzer (noir-lang/noir#8728) fix(fuzz): Use an inline block to circumvent negation with overflow (noir-lang/noir#8911) fix: Inline global arrays with functions at their call site (noir-lang/noir#8905) chore: Casting ACIR vs Brillig regression tests (noir-lang/noir#8903) fix(mem2reg): Keep last store for reference in array used only in an array get (noir-lang/noir#8877) fix: more SSA interpreter fixes (noir-lang/noir#8904) chore: Ban dynamic array indices with reference elements (noir-lang/noir#8888) chore(ssa_fuzzer): Add SSA validation to the SSA fuzzer (noir-lang/noir#8901) chore(fuzz): More metamorphic rules (noir-lang/noir#8857) fix: catch unbound type variables during frontend compilation (noir-lang/noir#8686) fix: preserve functions which are used in `array_set` instructions (noir-lang/noir#8891) fix: assorted SSA interpreter fixes (noir-lang/noir#8893) fix(ssa): Signed cast simplification (noir-lang/noir#8862) feat: simplify apply function cfg immediately (noir-lang/noir#8895) fix: do not hoist control dependent cast (noir-lang/noir#8886) fix(licm): Account for negative bounds when checking whether a loop executes (noir-lang/noir#8889) chore: Release Noir(1.0.0-beta.7) (noir-lang/noir#8520) chore: test noir-ecdsa library in CI (noir-lang/noir#8859) chore: Incorrect clippy warning blocking PRs (noir-lang/noir#8861) END_COMMIT_OVERRIDE --------- Co-authored-by: AztecBot <tech@aztecprotocol.com> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Description
Problem*
Resolves #8941
Summary*
Changes the order of "Dead Instruction Elimination" and "Brillig Array Get and Set Optimizations" in the
--minimal-ssapipeline to do the DIE as the last step.The reason is the Brillig array index optimisations shift constant indexes by an offset, and then insert the new constants into the DFG; when that happens the DFG tries to reuse existing constants and return their IDs, and these constants can come from the global as well as local values. If it comes from a global, it can mark a global value as used even when it wasn't otherwise referenced.
The DIE pass gathers used global values, but in the minimal pipeline it came before the index offsets, so it worked with stale data.
Additional Context
I don't know if this is an intended reuse, I suppose it might save some allocations the Brillig VM if we reuse global values, although it seems dubious if this is the only use of a global value. Nevertheless, swapping the order doesn't seem to have any detrimental effect.
Documentation*
Check one:
PR Checklist*
cargo fmton default settings.