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

feat(ssa): Replace values which have previously been constrained with simplified value #2483

Merged
merged 4 commits into from
Sep 5, 2023

Conversation

TomAFrench
Copy link
Member

Description

Problem*

Resolves

Summary*

This PR adds a mapping for ValueIds which are constrained to be equal within the current block. When resolving the inputs of instructions, we can then alternate between the standard resolution and checking for an constrained equivalence in this mapping.

This optimization is especially useful for situations where we want to perform slice indexing such as in https://github.com/AztecProtocol/aztec-packages/blob/94053e44f4d2a702fe9066bfff3cdd35e6d1b645/yarn-project/noir-libs/noir-aztec/src/messaging/l1_to_l2_message.nr#L47-L65. Rather than checking the slice length on each access, we can assert the length of the slice once and skip all of the other checks.

We must keep a separate cache rather than inserting these equivalences into the dfg as otherwise we'll apply these simplifications before (and inside) the constrain statement which enforces it.

Documentation

  • This PR requires documentation updates when merged.

    • I will submit a noir-lang/docs PR.
    • I will request for and support Dev Rel's help in documenting this PR.

Additional Context

The bytecode for a number of programs has increased due to previous PRs which didn't update the committed bytecode. The changes from this optimzation are in e4c9634

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

@jfecher jfecher left a comment

Choose a reason for hiding this comment

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

Since the scope of the constant_folding pass has expanded, can we add to its doc comment the new optimizations it is expected to do?

crates/noirc_evaluator/src/ssa/opt/constant_folding.rs Outdated Show resolved Hide resolved
crates/noirc_evaluator/src/ssa/opt/constant_folding.rs Outdated Show resolved Hide resolved
@TomAFrench TomAFrench marked this pull request as draft August 30, 2023 19:29
@TomAFrench TomAFrench changed the base branch from master to refactor-constant-folding September 2, 2023 00:55
Base automatically changed from refactor-constant-folding to master September 5, 2023 17:36
@TomAFrench TomAFrench force-pushed the replace_constrained_values branch 2 times, most recently from 5b50fb1 to 1590a79 Compare September 5, 2023 18:00
@TomAFrench TomAFrench marked this pull request as ready for review September 5, 2023 18:20
@TomAFrench
Copy link
Member Author

This is ready for a re-review now. CI failure is unrelated to this PR.

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

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

LGTM. I'm assuming the test is still failing though.

@TomAFrench TomAFrench added this pull request to the merge queue Sep 5, 2023
Merged via the queue into master with commit 9be750a Sep 5, 2023
13 checks passed
@TomAFrench TomAFrench deleted the replace_constrained_values branch September 5, 2023 20:04
TomAFrench added a commit that referenced this pull request Sep 5, 2023
* master:
  feat(ssa): Replace values which have previously been constrained with simplified value (#2483)
  fix: Black box func slice handling (#2562)
TomAFrench added a commit that referenced this pull request Sep 5, 2023
* master:
  fix(aztec): fix compilation of `aztec_library.rs` (#2567)
  feat(ssa): Replace values which have previously been constrained with simplified value (#2483)
  fix: Black box func slice handling (#2562)
  chore: Temporarily disable `noir_wasm` test (#2566)
  fix: Make def collector ordering more deterministic (#2515)
  chore: refactor `constant_folding` pass (#2533)
  chore: Cleanup mem2reg pass (#2531)
  chore: Replace hashers of hashmaps in dfg with fxhashes (#2490)
  chore: remove duplicate span from FunctionReturnType (#2546)
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.

2 participants