Skip to content

Conversation

@jfecher
Copy link
Contributor

@jfecher jfecher commented Jan 2, 2026

Description

Problem

Resolves #9838

Summary

Adds a new ssa pass mem2reg_simple based on https://bernsteinbear.com/assets/img/bebenita-ssa.pdf which itself is a summary of https://link.springer.com/content/pdf/10.1007/3-540-46423-9_8.pdf.

The algorithm is roughly:

  1. Create a block parameter for every possible variable in every possible block
  2. Figure out the value of each variable at the end of each block, forward that as a jmp argument to the next block
  3. For every block parameter, if the values passed to it from every jmp is the same, it can be removed and mapped to that value.

Or, again but in more detail:

  1. Pre-process our CFG to ensure that for each node with multiple predecessors, each of its predecessors will have only one successor - the original node. This is a work-around since we do not support block arguments on jmpif terminators.
  2. Collect every applicable variable to be optimized in the function. An applicable variable is a allocate instruction which is only used in the address field of store or load instructions - e.g. the address itself is never used in a first-class manner. Note that this excludes any variable that may be aliased, used in an array, function, etc.
  3. For each variable, add block arguments to every block that is dominated by the variable's declaration block.
  4. For each block, calculate:
    4.a. the value of each parameter at the start of the block (which will always just be the block argument)
    4.b. the value of each parameter at the end of the block (follow all the stores), optimizing out intermediate loads.
  5. Go through each block, adding the ending value of each variable as a terminator argument to pass to the next blocks.
  6. Go through each block's parameters. For each parameter, if the value of the jmp argument of all predecessor blocks is equal, the block parameter can be removed and we can map its value to the jmp value.

Additional Context

It turns out adding more block arguments to most blocks breaks a lot of things. Although by a lot of things it mostly just breaks unrolling in quite a few different ways. The process cfg mini pass also breaks unrolling's ability to identify all blocks in a loop, so that also had to be adjusted.

User Documentation

Check one:

  • No user documentation needed.
  • Changes in docs/ included in this PR.
  • [For Experimental Features] Changes in docs/ 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.

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 'ACVM Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: deca2cd Previous: dbdfe6f Ratio
perfectly_parallel_batch_inversion_opcodes 2790371 ns/iter (± 2019) 2262655 ns/iter (± 1808) 1.23

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

CC: @TomAFrench

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: 8a72a40 Previous: 0db6c97 Ratio
test_report_zkpassport_noir-ecdsa_ 2 s 1 s 2
test_report_zkpassport_noir_rsa_ 1 s 0 s +∞

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

CC: @TomAFrench

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 'Compilation Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 8a72a40 Previous: 0db6c97 Ratio
rollup-tx-base-private 27.72 s 19.12 s 1.45
rollup-tx-base-public 131.8 s 80.78 s 1.63

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

CC: @TomAFrench

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 'Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: deca2cd Previous: dbdfe6f Ratio
rollup-root 0.005 s 0.004 s 1.25

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

CC: @TomAFrench

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 'Opcode count'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.10.

Benchmark suite Current: 8a72a40 Previous: 0db6c97 Ratio
rollup-tx-merge 1504 opcodes 1304 opcodes 1.15

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

CC: @TomAFrench

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 'Execution Memory'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 8a72a40 Previous: 0db6c97 Ratio
rollup-checkpoint-root-single-block 2140 MB 1760 MB 1.22
rollup-checkpoint-root 2140 MB 1760 MB 1.22

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

CC: @TomAFrench

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 'Brillig Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 8a72a40 Previous: 0db6c97 Ratio
rollup-tx-merge 0.002 s 0.001 s 2

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

CC: @TomAFrench

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split mem2reg into separate passes

2 participants