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: Add additional BinaryOp simplifications #2124

Merged
merged 1 commit into from
Aug 2, 2023

Conversation

TomAFrench
Copy link
Member

@TomAFrench TomAFrench commented Aug 2, 2023

Description

Problem*

Resolves

Summary*

This PR adds additional simplification rules for BinaryOps for special cases of the operations where the operation is a no-op.

fn main(x: u32) -> distinct pub [u32; 3] {
    let mut result : [u32; 3] = [0; 3];
    result[0] = x ^ 0;
    result[1] = x & x;
    result[2] = x | x;
    result
}

On the latest nightly this compiles to

Compiled ACIR for main (unoptimized):
current witness index : 11
public parameters indices : []
return value indices : [9, 10, 11]
BLACKBOX::RANGE [(_1, num_bits: 32)] [ ]
EXPR [ (-1, _2) 0 ]
BLACKBOX::XOR [(_1, num_bits: 32), (_2, num_bits: 32)] [ _3]
BLACKBOX::AND [(_1, num_bits: 32), (_1, num_bits: 32)] [ _4]
EXPR [ (-1, _1) (-1, _5) 4294967295 ]
EXPR [ (-1, _1) (-1, _6) 4294967295 ]
BLACKBOX::AND [(_5, num_bits: 32), (_6, num_bits: 32)] [ _7]
EXPR [ (-1, _7) (-1, _8) 4294967295 ]
EXPR [ (1, _3) (-1, _9) 0 ]
EXPR [ (1, _4) (-1, _10) 0 ]
EXPR [ (1, _8) (-1, _11) 0 ]

With this PR, this is compiled down to

Compiled ACIR for main (unoptimized):
current witness index : 4
public parameters indices : []
return value indices : [2, 3, 4]
BLACKBOX::RANGE [(_1, num_bits: 32)] [ ]
EXPR [ (1, _1) (-1, _2) 0 ]
EXPR [ (1, _1) (-1, _3) 0 ]
EXPR [ (1, _1) (-1, _4) 0 ]

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

PR Checklist*

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

BEGIN_COMMIT_OVERRIDE
feat(ssa): Add additional BinaryOp simplifications (#2124)
END_COMMIT_OVERRIDE

@TomAFrench TomAFrench requested a review from jfecher August 2, 2023 13:03
@TomAFrench TomAFrench changed the title feat: add additional BinaryOp simplifications feat: Add additional BinaryOp simplifications Aug 2, 2023
Copy link
Contributor

@vezenovm vezenovm left a comment

Choose a reason for hiding this comment

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

LGTM

@TomAFrench TomAFrench added this pull request to the merge queue Aug 2, 2023
Merged via the queue into master with commit 50b2816 Aug 2, 2023
7 checks passed
@TomAFrench TomAFrench deleted the binary-simplification branch August 2, 2023 13:37
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master:
  feat: Add support for bitshifts by distances known at runtime (#2072)
  feat: Add additional `BinaryOp` simplifications (#2124)
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master: (50 commits)
  fix(globals): Accurately filter literals for resolving globals (#2126)
  feat: Optimize away constant calls to black box functions (#1981)
  fix: Rename `Option::value` to `Option::_value` (#2127)
  feat: replace boolean `AND`s with multiplication (#1954)
  chore: create a `const` to hold the panic message (#2122)
  feat: Add support for bitshifts by distances known at runtime (#2072)
  feat: Add additional `BinaryOp` simplifications (#2124)
  fix: flattening pass no longer overwrites previously mapped condition values (#2117)
  chore(noirc_driver): Unify crate preparation (#2119)
  feat!: Support workspaces and package selection on every nargo command (#1992)
  chore: Make a more clear error for slices passed to std::println (#2113)
  feat: Implement type aliases (#2112)
  feat: Add `Option<T>` to noir stdlib (#1781)
  feat: Format strings for prints  (#1952)
  feat(acir_gen): RecursiveAggregation opcode and updates to black box func call generation (#2097)
  fix: Mutating a variable no longer mutates its copy (#2057)
  fix: Implement `.len()` in Acir-Gen (#2077)
  chore: clippy fixes (#2101)
  chore: Update `noir-source-resolver` to v1.1.3 (#1912)
  chore: Document `GeneratedAcir::more_than_eq_comparison` (#2085)
  ...
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master:
  chore: rename `ssa_refactor` module to `ssa` (#2129)
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
  fix(globals): Accurately filter literals for resolving globals (#2126)
  feat: Optimize away constant calls to black box functions (#1981)
  fix: Rename `Option::value` to `Option::_value` (#2127)
  feat: replace boolean `AND`s with multiplication (#1954)
  chore: create a `const` to hold the panic message (#2122)
  feat: Add support for bitshifts by distances known at runtime (#2072)
  feat: Add additional `BinaryOp` simplifications (#2124)
  fix: flattening pass no longer overwrites previously mapped condition values (#2117)
  chore(noirc_driver): Unify crate preparation (#2119)
  feat!: Support workspaces and package selection on every nargo command (#1992)
  chore: Make a more clear error for slices passed to std::println (#2113)
  feat: Implement type aliases (#2112)
  feat: Add `Option<T>` to noir stdlib (#1781)
  feat: Format strings for prints  (#1952)
  feat(acir_gen): RecursiveAggregation opcode and updates to black box func call generation (#2097)
  fix: Mutating a variable no longer mutates its copy (#2057)
  fix: Implement `.len()` in Acir-Gen (#2077)
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master:
  chore: rename `ssa_refactor` module to `ssa` (#2129)
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
  fix(globals): Accurately filter literals for resolving globals (#2126)
  feat: Optimize away constant calls to black box functions (#1981)
  fix: Rename `Option::value` to `Option::_value` (#2127)
  feat: replace boolean `AND`s with multiplication (#1954)
  chore: create a `const` to hold the panic message (#2122)
  feat: Add support for bitshifts by distances known at runtime (#2072)
  feat: Add additional `BinaryOp` simplifications (#2124)
  fix: flattening pass no longer overwrites previously mapped condition values (#2117)
  chore(noirc_driver): Unify crate preparation (#2119)
  feat!: Support workspaces and package selection on every nargo command (#1992)
  chore: Make a more clear error for slices passed to std::println (#2113)
  feat: Implement type aliases (#2112)
  feat: Add `Option<T>` to noir stdlib (#1781)
  feat: Format strings for prints  (#1952)
  feat(acir_gen): RecursiveAggregation opcode and updates to black box func call generation (#2097)
  fix: Mutating a variable no longer mutates its copy (#2057)
  fix: Implement `.len()` in Acir-Gen (#2077)
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master:
  chore: rename `ssa_refactor` module to `ssa` (#2129)
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
  fix(globals): Accurately filter literals for resolving globals (#2126)
  feat: Optimize away constant calls to black box functions (#1981)
  fix: Rename `Option::value` to `Option::_value` (#2127)
  feat: replace boolean `AND`s with multiplication (#1954)
  chore: create a `const` to hold the panic message (#2122)
  feat: Add support for bitshifts by distances known at runtime (#2072)
  feat: Add additional `BinaryOp` simplifications (#2124)
  fix: flattening pass no longer overwrites previously mapped condition values (#2117)
  chore(noirc_driver): Unify crate preparation (#2119)
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