chore(ssa): Activate loop invariant code motion on ACIR functions #6785
+3
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
PR Checklist*
cargo fmt
on default settings.