Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ssa): Activate loop invariant code motion on ACIR functions #6785

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vezenovm
Copy link
Contributor

Description

Problem*

Part of general effort to optimize the compiler.

Summary*

Loop invariant code motion most affects Brillig as in that runtime we actually keep loops and may possibly re-execute unnecessary instructions. In ACIR all loops are unrolled so when the pass was introduced I was thinking that running it may be an unnecessary cost when compiling to ACIR. However, the pass should provide benefits to the compilation pipeline itself.

For ACIR programs with large upper loop bounds, unrolling is oftentimes the pass that takes up the most time. If we can reduce the number of opcodes inside of a loop, unrolling should take less time. This becomes most obvious when paired with #6782, as a large constant array it most likely going to be one of the heavier instructions to process due to its large number of values.

We probably will want some kind of heuristic to determine whether it is worth it to run this pass for ACIR. Running this pass in ACIR is still most likely unnecessary for the majority of programs, but will benefit those programs with lots of heavy loop invariants.

Additional Context

Compiling the blob circuit:
Master:
Loop invariant code motion - 0ms
Unrolling - 44s
This branch w/ #6784:
Loop invariant code motion - 152ms
Unrolling - 27s (38.6% improvement)

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.

Copy link
Contributor

github-actions bot commented Dec 12, 2024

Peak Memory Sample

Program Peak Memory %
keccak256 79.14M 1%
workspace 121.86M -1%
regression_4709 295.98M 0%
ram_blowup_regression 2.44G 0%
private-kernel-tail 210.14M 0%
private-kernel-reset 861.45M 0%
private-kernel-inner 307.67M 0%
parity-root 175.70M 0%

Copy link
Contributor

github-actions bot commented Dec 12, 2024

Compilation Sample

Program Compilation Time %
sha256_regression 0m1.417s -5%
regression_4709 0m0.735s -52%
ram_blowup_regression 0m16.997s -1%
private-kernel-tail 0m1.411s 11%
private-kernel-reset 0m9.305s 4%
private-kernel-inner 0m2.696s 16%
parity-root 0m0.829s -28%
noir-contracts 2m54.002s 9%

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.

1 participant