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

Hoist constants shared across functions into the global space #7109

Open
vezenovm opened this issue Jan 17, 2025 · 0 comments
Open

Hoist constants shared across functions into the global space #7109

vezenovm opened this issue Jan 17, 2025 · 0 comments
Assignees
Labels
brillig Unconstrained functions / brillig IR enhancement New feature or request ssa

Comments

@vezenovm
Copy link
Contributor

vezenovm commented Jan 17, 2025

Problem

Post #7021 we will have globals from SSA fully implemented in Brillig.

However, we do not account for shared local constants across functions. For example let's take this simplified version of global_var_regression_simple

global EXPONENTIATE: [[Field; 2]; 2] = [[1, 1], [0, 0]];

fn main(x: Field, y: pub Field) {
    let mut acc: Field = 0;
    for i in 0..2 {
        for j in 0..2 {
            acc += EXPONENTIATE[i][j];
        }
    }
    assert(x != y);
    dummy_again(x, y);
}
fn dummy_again(x: Field, y: Field) {
    let mut acc: Field = 0;
    for i in 0..2 {
        for j in 0..2 {
            acc += EXPONENTIATE[i][j];
        }
    }
    assert(x != y);
}

Running nargo info --force-brillig --inliner-aggressiveness -9223372036854775808 --profile-execution will give you 178 opcodes executed.

If we made a global ZERO: Field = 0 and used that to initialize acc in both functions the opcodes executed would go down to 176. This is a pretty small example, but for larger programs with lots of constants performing this hoisting could be quite beneficial.

Happy Case

We should be able to automatically hoist constants shared across functions into the global space. We should not have any repeated initialization of constants.

Workaround

Yes

Workaround Description

Manually writing globals that are shared across functions

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

This provides execution benefits, so even though it is not a true blocker, it is high priority.

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@vezenovm vezenovm added brillig Unconstrained functions / brillig IR enhancement New feature or request ssa labels Jan 17, 2025
@vezenovm vezenovm self-assigned this Jan 17, 2025
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jan 17, 2025
@vezenovm vezenovm changed the title Hoisting constants shared across functions into the global space Hoist constants shared across functions into the global space Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brillig Unconstrained functions / brillig IR enhancement New feature or request ssa
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant