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

Optimize arithmetic across multiple instructions #5707

Open
jfecher opened this issue Aug 9, 2024 · 0 comments
Open

Optimize arithmetic across multiple instructions #5707

jfecher opened this issue Aug 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Aug 9, 2024

Problem

Currently when simplifying instructions we only look at one instruction at a time for the most part.

For example, the program:

fn main(x: Field) {
    let x2 = x + 1 - 1;
    assert_eq(x, x2);
}

Does not optimize out x2:

After Array Set Optimizations:
acir(inline) fn main f0 {
  b0(v0: Field):
    v9 = add v0, Field 1
    v10 = sub v9, Field 1
    constrain v0 == v10
    return 
}

Happy Case

There are many cases when multiple instructions could constant combine like this so I won't list them all. Another case as mentioned in #5691 is with addition and less than which can show up in length checks of arrays in some cases:

v23 = add v21, u32 1
v28 = lt v23, u32 9

Which could be simplified to:

v23 = lt v21, u32 8

There are a lot of checks we could add but I think this could be a relatively easy optimization win still since I anticipate patterns like this will show up in user code either directly or as the result of previous optimizations as in the lt case above.

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant