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 refactor): Simplify inlining pass and fix inlining failure #1337

Merged
merged 4 commits into from
May 12, 2023

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented May 11, 2023

Related issue(s)

Resolves #

Description

Summary of changes

This simplifies the inlining pass by removing the extra block that is inserted for return instructions to jump to. Instead, when a function call is inlined we just switch back to the same block as the return instruction. The result is fewer blocks created which allows the code in issue #1327 to compile properly in the ssa refactoring without needing a block simplification pass afterward and subsequent second inlining.

Dependency additions / changes

Test additions / changes

I've added a unit test for the issue in #1327, although the issue is still open since the experimental ssa refactor is not ready to be the default IR.

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.

Documentation needs

  • This PR requires documentation updates when merged.

Additional context

@jfecher jfecher requested a review from joss-aztec May 11, 2023 14:47
@jfecher
Copy link
Contributor Author

jfecher commented May 11, 2023

To elaborate, previously the code in that issue would compile to (after inlining):

fn d_method f1 {
  b0(v0: Field):
    v2 = mul v0, v0
    return v2
}
fn main f4 {
  b0(v0: Field):
    jmp b2(f1)
  b2(v3: function):
    jmp b3(v3)
  b3(v5: function):
    v6 = call v5(v0)
    return v6
}

Note the extra blocks in main. The function being passed through block parameters made it so inlining couldn't see what function was referred to by v5 and failed to inline the final call. With this PR the extra blocks created from function calls are eliminated and the new IR is:

fn main f4 {
  b0(v0: Field):
    v4 = mul v0, v0
    return v4
}

@kevaundray kevaundray added this pull request to the merge queue May 11, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch May 11, 2023
@kevaundray kevaundray enabled auto-merge May 12, 2023 14:43
@kevaundray kevaundray added this pull request to the merge queue May 12, 2023
Merged via the queue into master with commit 7df3bb1 May 12, 2023
@kevaundray kevaundray deleted the jf/ssa-inlining-simplify branch May 12, 2023 15:55
TomAFrench added a commit that referenced this pull request May 17, 2023
* master: (66 commits)
  feat(nargo)!: retire print-acir in favour of flag (#1328)
  chore(ssa): enable cse for assert (#1350)
  chore(ssa refactor): Add basic instruction simplification (#1329)
  chore(noir): Release 0.6.0 (#1279)
  feat: enable to_radix for any field element (#1343)
  chore(ssa refactor): Simplify inlining pass and fix inlining failure (#1337)
  chore!: Update to acvm 0.11.0 (#1322)
  feat: Add ECDSA secp256k1 builtin test (#1294)
  chore: add support for encoding/decoding inputs from JSON (#1325)
  feat: Issue an error when attempting to use a `return` expression (#1330)
  chore(ssa refactor): Fix inlining bug (#1335)
  fix: to-bits and to-radix for > 128 bits (#1312)
  chore(parser): Parser error optimisation (#1292)
  chore(ssa refactor): Implement function inlining (#1293)
  chore: fix installation link in readme (#1326)
  chore: fix installation link in readme (#1326)
  feat(stdlib): Add keccak (#1249)
  fix: Parsing nested generics (#1319)
  chore(ssa refactor): Document some SSA-gen functions (#1321)
  fix: Assigning to tuple fields (#1318)
  ...
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