Skip to content

feat(ssa): Mark transitively dead parameters during DIE#8254

Merged
TomAFrench merged 33 commits intomasterfrom
mv/prune-transitively-dead-params
May 8, 2025
Merged

feat(ssa): Mark transitively dead parameters during DIE#8254
TomAFrench merged 33 commits intomasterfrom
mv/prune-transitively-dead-params

Conversation

@vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Apr 28, 2025

Description

Problem*

Resolves #8239 (comment)

Summary*

Transtively dead parameters will now be removed during DIE.
For example this code:

Details

        brillig(inline) predicate_pure fn main f0 {
          b0(v0: i16):
            v5 = lt i16 3, v0
            jmpif v5 then: b1, else: b2
          b1():
            v8 = lt i16 4, v0
            jmpif v8 then: b3, else: b4
          b2():
            jmp b5(Field 3)
          b3():
            jmp b6(Field 1)
          b4():
            jmp b6(Field 2)
          b5(v1: Field):
            v12 = lt i16 5, v0
            jmpif v12 then: b7, else: b8
          b6(v2: Field):
            jmp b5(v2)
          b7():
            jmp b9(v1)
          b8():
            v13 = add v1, Field 1
            jmp b9(v13)
          b9(v3: Field):
            return
        }

Will become the following:

Details

        brillig(inline) predicate_pure fn main f0 {
          b0(v0: i16):
            v2 = lt i16 3, v0
            jmpif v2 then: b1, else: b2
          b1():
            v4 = lt i16 4, v0
            jmpif v4 then: b3, else: b4
          b2():
            jmp b5()
          b3():
            jmp b6()
          b4():
            jmp b6()
          b5():
            v6 = lt i16 5, v0
            jmpif v6 then: b7, else: b8
          b6():
            jmp b5()
          b7():
            jmp b9()
          b8():
            jmp b9()
          b9():
            return
        }

This was done in the following way:

  1. A keep list was maintained per block during DIE.
    As per the doc comments:
    /// A per-block list indicating which block parameters are still considered alive.
    ///
    /// Each entry maps a [BasicBlockId] to a `Vec<bool>`, where the `i`th boolean corresponds to
    /// the `i`th parameter of that block. A value of `true` means the parameter is used and should
    /// be preserved. A value of `false` means it is unused and can be pruned.
    ///
    /// This keep list is used during terminator analysis to avoid incorrectly marking values as used
    /// simply because they appear as terminator arguments. Only parameters marked as live here
    /// should result in values being marked as used in terminator arguments.
  1. DIE now runs in a feedback loop with pruning. This was a conscious choice to keep DIE and pruning separated and allow for easier testing of the separate passes.
  2. Preprocess functions had to be updated to not run DIE in isolation on a function as we now mark terminator arguments potentially unused during DIE. It must be run over the full SSA.

Additional Context

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Base automatically changed from mv/prune-dead-params to master April 28, 2025 21:11
@vezenovm vezenovm force-pushed the mv/prune-transitively-dead-params branch from b69f2ed to 8521c89 Compare April 28, 2025 21:53
@vezenovm vezenovm added the bench-show Display benchmark results on PR label Apr 30, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACVM Benchmarks

Details
Benchmark suite Current: 8c5e7e9 Previous: a593e48 Ratio
purely_sequential_opcodes 273376 ns/iter (± 476) 264740 ns/iter (± 520) 1.03
perfectly_parallel_opcodes 244789 ns/iter (± 4233) 234841 ns/iter (± 3881) 1.04
perfectly_parallel_batch_inversion_opcodes 3584084 ns/iter (± 13150) 3221519 ns/iter (± 4324) 1.11

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compilation Time

Details
Benchmark suite Current: 8c5e7e9 Previous: a593e48 Ratio
regression_4709 0.675 s 0.675 s 1
ram_blowup_regression 12.8 s 12.7 s 1.01
global_var_regression_entry_points 0.358 s 0.49 s 0.73
private-kernel-inner 2.322 s 2.212 s 1.05
private-kernel-reset 6.738 s 6.55 s 1.03
private-kernel-tail 1.126 s 1.166 s 0.97
rollup-base-private 17.92 s 18.92 s 0.95
rollup-base-public 13.1 s 13.32 s 0.98
rollup-block-root-empty 1.282 s 1.256 s 1.02
rollup-block-root-single-tx 124 s 124 s 1
rollup-block-root 119 s 135 s 0.88
rollup-merge 1.066 s 1.14 s 0.94
rollup-root 1.62 s 1.67 s 0.97

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execution Time

Details
Benchmark suite Current: 8c5e7e9 Previous: a593e48 Ratio
private-kernel-inner 0.028 s 0.027 s 1.04
private-kernel-reset 0.164 s 0.163 s 1.01
private-kernel-tail 0.016 s 0.016 s 1
rollup-base-private 0.331 s 0.333 s 0.99
rollup-base-public 0.212 s 0.212 s 1
rollup-block-root 11.4 s 11.6 s 0.98
rollup-merge 0.004 s 0.004 s 1
rollup-root 0.013 s 0.013 s 1

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Suite Duration

Details
Benchmark suite Current: 8c5e7e9 Previous: a593e48 Ratio
test_report_AztecProtocol_aztec-packages_noir-projects_aztec-nr 54 s 52 s 1.04
test_report_AztecProtocol_aztec-packages_noir-projects_noir-contracts 90 s 98 s 0.92
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob 42 s 39 s 1.08
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_private-kernel-lib 178 s 172 s 1.03
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_rollup-lib 191 s 186 s 1.03
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_types 54 s 55 s 0.98
test_report_noir-lang_noir-bignum_ 412 s 401 s 1.03
test_report_noir-lang_noir_bigcurve_ 230 s 222 s 1.04
test_report_noir-lang_sha512_ 28 s 27 s 1.04
test_report_zkpassport_noir_rsa_ 22 s 22 s 1

This comment was automatically generated by workflow using github-action-benchmark.

@vezenovm vezenovm marked this pull request as ready for review May 2, 2025 14:37
@vezenovm vezenovm requested a review from a team May 2, 2025 14:43
@vezenovm
Copy link
Contributor Author

vezenovm commented May 2, 2025

to_bytes_consistent_inliner_zero 122 (+53) +76.81%

I will make a follow-up issue for this regression. This actually looks to be due DIE being run over the full SSA during the preprocess fns pass which is changing inlining.

EDIT: #8321

Copy link
Collaborator

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vezenovm
Copy link
Contributor Author

vezenovm commented May 5, 2025

arb_program_can_be_executed looks to be failing with a panic post the last master merge. Going to need to investigate that failure before merging.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: a2c22d6 Previous: ff795cf Ratio
test_report_noir-lang_noir_bigcurve_ 285 s 235 s 1.21

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@vezenovm
Copy link
Contributor Author

vezenovm commented May 7, 2025

arb_program_can_be_executed looks to be failing with a panic post the last master merge. Going to need to investigate that failure before merging.

Here is the panic we see triggered during that test. It can be triggered on master so I am going to resolve it separately. It is currently blocking this PR.

@vezenovm vezenovm added the Blocked PR is blocked on an issue label May 7, 2025
@vezenovm
Copy link
Contributor Author

vezenovm commented May 8, 2025

Here is the panic we see triggered during that test. It can be triggered on master so I am going to resolve it separately. It is currently blocking this PR.

No longer getting a panic on the 0xd683001500100000 seed after #8426 and arb_program_can_be_executed passes.

@vezenovm vezenovm enabled auto-merge May 8, 2025 20:38
@vezenovm vezenovm removed the Blocked PR is blocked on an issue label May 8, 2025
@vezenovm vezenovm disabled auto-merge May 8, 2025 20:38
@TomAFrench TomAFrench added this pull request to the merge queue May 8, 2025
Merged via the queue into master with commit 2902503 May 8, 2025
116 checks passed
@TomAFrench TomAFrench deleted the mv/prune-transitively-dead-params branch May 8, 2025 22:11
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request May 12, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: always type-check turbofish, and error when it's not allowed
(noir-lang/noir#8437)
chore: Release Noir(1.0.0-beta.5)
(noir-lang/noir#7955)
feat(greybox_fuzzer): Parallel fuzz tests
(noir-lang/noir#8432)
fix(ssa): Mislabeled instructions with side effects in
EnableSideEffectsIf removal pass
(noir-lang/noir#8355)
feat: SSA pass impact report
(noir-lang/noir#8393)
chore: bump external pinned commits
(noir-lang/noir#8433)
chore: separate benchmarking from github actions more
(noir-lang/noir#7943)
chore(fuzz): Break up the AST fuzzer `compare` module
(noir-lang/noir#8431)
chore(fuzz): Rename `init_vs_final` to `min_vs_full`
(noir-lang/noir#8430)
fix!: error on tuple mismatch
(noir-lang/noir#8424)
chore: bump external pinned commits
(noir-lang/noir#8429)
chore(acir): Test whether the predicate has an effect on slice
intrinsics (noir-lang/noir#8421)
feat(ssa): Mark transitively dead parameters during DIE
(noir-lang/noir#8254)
fix(ssa_gen): Do not code gen fetching of empty arrays when initializing
the data bus (noir-lang/noir#8426)
chore: remove `.aztec-sync-commit`
(noir-lang/noir#8415)
chore(test): Add more unit tests for
`inline_functions_with_at_most_one_instruction`
(noir-lang/noir#8418)
chore: add minor docs for interpreter
(noir-lang/noir#8397)
fix: print slice composite types surrounded by parentheses
(noir-lang/noir#8412)
feat: Skip SSA passes that contain any of the given messages
(noir-lang/noir#8416)
fix: disable range constraints using the predicate
(noir-lang/noir#8396)
chore: bumping external libraries
(noir-lang/noir#8406)
chore: redo typo PR by shystrui1199
(noir-lang/noir#8405)
feat(test): add `nargo_fuzz_target`
(noir-lang/noir#8308)
fix: allow names to collide in the values/types namespaces
(noir-lang/noir#8286)
fix: Fix sequencing of side-effects in lvalue
(noir-lang/noir#8384)
feat(greybox_fuzzer): Maximum executions parameter added
(noir-lang/noir#8390)
fix: warn on and discard unreachable statements after break and continue
(noir-lang/noir#8382)
fix: add handling for u128 infix ops in interpreter
(noir-lang/noir#8392)
chore: move acirgen tests into separate file
(noir-lang/noir#8376)
feat(fuzz): initial version of comptime vs brillig target for AST fuzzer
(noir-lang/noir#8335)
chore: apply lints to `ast_fuzzer`
(noir-lang/noir#8386)
chore: add note on AI generated PRs in `CONTRIBUTING.md`
(noir-lang/noir#8385)
chore: document flattening pass
(noir-lang/noir#8312)
fix: comptime shift-right overflow is zero
(noir-lang/noir#8380)
feat: let static_assert accept any type for its message
(noir-lang/noir#8322)
fix(expand): output safety comment before statements
(noir-lang/noir#8378)
chore: avoid need to rebuild after running tests
(noir-lang/noir#8379)
chore: bump dependencies (noir-lang/noir#8372)
chore: Add GITHUB_TOKEN to cross build
(noir-lang/noir#8370)
chore: redo typo PR by GarmashAlex
(noir-lang/noir#8364)
chore: remove unsafe code from greybox fuzzer
(noir-lang/noir#8315)
feat: add `--fuzz-timeout` to `nargo test` options
(noir-lang/noir#8326)
chore: bump external pinned commits
(noir-lang/noir#8334)
fix(expand): try to use "Self" in function calls
(noir-lang/noir#8353)
fix: Fix evaluation order of assignments with side-effects in their rhs
(noir-lang/noir#8342)
fix: let comptime Field value carry the field's sign
(noir-lang/noir#8343)
fix: Ordering of items in callstacks
(noir-lang/noir#8338)
chore: add snapshosts for nargo expand tests
(noir-lang/noir#8318)
fix(ownership): Clone global arrays
(noir-lang/noir#8328)
chore: Replace all SSA interpreter panics with error variants
(noir-lang/noir#8311)
feat: Metamorphic AST fuzzing
(noir-lang/noir#8299)
fix: fix some Display implementations for AST nodes
(noir-lang/noir#8316)
chore: remove leftover file
(noir-lang/noir#8313)
fix: uses non-zero points with ec-add-unsafe
(noir-lang/noir#8248)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request May 12, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: always type-check turbofish, and error when it's not allowed
(noir-lang/noir#8437)
chore: Release Noir(1.0.0-beta.5)
(noir-lang/noir#7955)
feat(greybox_fuzzer): Parallel fuzz tests
(noir-lang/noir#8432)
fix(ssa): Mislabeled instructions with side effects in
EnableSideEffectsIf removal pass
(noir-lang/noir#8355)
feat: SSA pass impact report
(noir-lang/noir#8393)
chore: bump external pinned commits
(noir-lang/noir#8433)
chore: separate benchmarking from github actions more
(noir-lang/noir#7943)
chore(fuzz): Break up the AST fuzzer `compare` module
(noir-lang/noir#8431)
chore(fuzz): Rename `init_vs_final` to `min_vs_full`
(noir-lang/noir#8430)
fix!: error on tuple mismatch
(noir-lang/noir#8424)
chore: bump external pinned commits
(noir-lang/noir#8429)
chore(acir): Test whether the predicate has an effect on slice
intrinsics (noir-lang/noir#8421)
feat(ssa): Mark transitively dead parameters during DIE
(noir-lang/noir#8254)
fix(ssa_gen): Do not code gen fetching of empty arrays when initializing
the data bus (noir-lang/noir#8426)
chore: remove `.aztec-sync-commit`
(noir-lang/noir#8415)
chore(test): Add more unit tests for
`inline_functions_with_at_most_one_instruction`
(noir-lang/noir#8418)
chore: add minor docs for interpreter
(noir-lang/noir#8397)
fix: print slice composite types surrounded by parentheses
(noir-lang/noir#8412)
feat: Skip SSA passes that contain any of the given messages
(noir-lang/noir#8416)
fix: disable range constraints using the predicate
(noir-lang/noir#8396)
chore: bumping external libraries
(noir-lang/noir#8406)
chore: redo typo PR by shystrui1199
(noir-lang/noir#8405)
feat(test): add `nargo_fuzz_target`
(noir-lang/noir#8308)
fix: allow names to collide in the values/types namespaces
(noir-lang/noir#8286)
fix: Fix sequencing of side-effects in lvalue
(noir-lang/noir#8384)
feat(greybox_fuzzer): Maximum executions parameter added
(noir-lang/noir#8390)
fix: warn on and discard unreachable statements after break and continue
(noir-lang/noir#8382)
fix: add handling for u128 infix ops in interpreter
(noir-lang/noir#8392)
chore: move acirgen tests into separate file
(noir-lang/noir#8376)
feat(fuzz): initial version of comptime vs brillig target for AST fuzzer
(noir-lang/noir#8335)
chore: apply lints to `ast_fuzzer`
(noir-lang/noir#8386)
chore: add note on AI generated PRs in `CONTRIBUTING.md`
(noir-lang/noir#8385)
chore: document flattening pass
(noir-lang/noir#8312)
fix: comptime shift-right overflow is zero
(noir-lang/noir#8380)
feat: let static_assert accept any type for its message
(noir-lang/noir#8322)
fix(expand): output safety comment before statements
(noir-lang/noir#8378)
chore: avoid need to rebuild after running tests
(noir-lang/noir#8379)
chore: bump dependencies (noir-lang/noir#8372)
chore: Add GITHUB_TOKEN to cross build
(noir-lang/noir#8370)
chore: redo typo PR by GarmashAlex
(noir-lang/noir#8364)
chore: remove unsafe code from greybox fuzzer
(noir-lang/noir#8315)
feat: add `--fuzz-timeout` to `nargo test` options
(noir-lang/noir#8326)
chore: bump external pinned commits
(noir-lang/noir#8334)
fix(expand): try to use "Self" in function calls
(noir-lang/noir#8353)
fix: Fix evaluation order of assignments with side-effects in their rhs
(noir-lang/noir#8342)
fix: let comptime Field value carry the field's sign
(noir-lang/noir#8343)
fix: Ordering of items in callstacks
(noir-lang/noir#8338)
chore: add snapshosts for nargo expand tests
(noir-lang/noir#8318)
fix(ownership): Clone global arrays
(noir-lang/noir#8328)
chore: Replace all SSA interpreter panics with error variants
(noir-lang/noir#8311)
feat: Metamorphic AST fuzzing
(noir-lang/noir#8299)
fix: fix some Display implementations for AST nodes
(noir-lang/noir#8316)
chore: remove leftover file
(noir-lang/noir#8313)
fix: uses non-zero points with ec-add-unsafe
(noir-lang/noir#8248)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bench-show Display benchmark results on PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants