Skip to content

Add option to treat literal assignments as operations in SSACFGs #16041

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

Merged
merged 2 commits into from
May 12, 2025

Conversation

clonker
Copy link
Member

@clonker clonker commented May 9, 2025

Previously, something like

{
    let a := 42
    mstore(a, a)
}

would have lead to mstore(42, 42). This PR adds a bool option to the SSACFG builder, which leaves the variable and assignment intact. This can have nontrivial impact on liveness analysis and stacklayout generation. Which one turns out to be better all in all remains to be seen, hence the old behavior is not simply replaced but can be switched on and off.

@clonker clonker requested a review from r0qs May 9, 2025 14:29
@clonker clonker added the 🟡 PR review label label May 9, 2025
@clonker clonker force-pushed the ssacfg_treat_literals_as_variables branch from c6083a4 to d07b3c2 Compare May 9, 2025 14:30
Copy link

@BoomchainLabs BoomchainLabs left a comment

Choose a reason for hiding this comment

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

Lgtm

@blishko
Copy link
Contributor

blishko commented May 9, 2025

What's the problem with simplifying to mstore(42,42)?

@clonker
Copy link
Member Author

clonker commented May 9, 2025

It is not a problem per se. Sometimes though it can be useful to track constants through variables instead of (and that's the status quo for the SSA CFG Codegen) using them as push constants exclusively, as that can have a positive effect on the bytecode size. Especially for large constants. A PUSH32 needs one byte for the instruction and 32 bytes for the value. SWAP and DUP are one byte each.
While not the root cause, we currently do have some problems with codebloat in the ssa cfg codegen, so this may mitigate it a bit.
And it might make results behave a little differently when it comes to greedy algorithms for stacklayout scheduling, ie, the project that the Madrid collab is working on. In any case at this point it is something to try and see how well it fares.

nikola-matic
nikola-matic previously approved these changes May 12, 2025
@clonker clonker force-pushed the ssacfg_treat_literals_as_variables branch from d07b3c2 to d790750 Compare May 12, 2025 09:07
@clonker clonker enabled auto-merge May 12, 2025 09:17
@clonker clonker merged commit 47f859b into develop May 12, 2025
74 checks passed
@clonker clonker deleted the ssacfg_treat_literals_as_variables branch May 12, 2025 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🟡 PR review label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants