Skip to content

SSA: Refactor shuffler helper and add a case to prefer swap if still possible instead of shrinking first - #16515

Merged
clonker merged 2 commits into
developfrom
ssa-cfg-shuffler-updates
Mar 19, 2026
Merged

SSA: Refactor shuffler helper and add a case to prefer swap if still possible instead of shrinking first#16515
clonker merged 2 commits into
developfrom
ssa-cfg-shuffler-updates

Conversation

@blishko

@blishko blishko commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

This PR consists of two changes in two separate commits. I recommend to review the commits separately.
First one is proposal to refactor shufller's helper dupDeepSlotIfRequired.
It attempts to make the code more compact to facilitate reading and understanding this method.
It also extracts a check to a helper function on State. This helper is then reused in the second commit where we attempt to check if a slot is swap-reachable even if it is not dup-reachable. If is swap reachable and the swap is safe to do, we do it, instead of first attempting to shrink the stack (in order to bring this slot into dup-reachable space).

On deep_argument_shrink test case this produces locally better bytecode.
It would be good to run a larger evaluation on larger contracts to see what is the effect of this change.

@blishko
blishko requested a review from clonker March 12, 2026 10:30
clonker
clonker previously approved these changes Mar 18, 2026

@clonker clonker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just two tiny stylistic points, beyond that good change! Makes the code easier to reason about, too.

Comment thread libyul/backends/evm/ssa/StackShuffler.cpp Outdated
Comment thread libyul/backends/evm/ssa/StackShuffler.cpp Outdated
{
auto const & top = m_stackData.back();
yulAssert(_offset.value < size());
auto const & slot = m_stackData[_offset.value];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe StackData should get these accessors with offset and depth, too :) not in this PR in any case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It could be helpful :)

blishko added 2 commits March 18, 2026 14:51
Previously, if a slot is desirable to be dupped, but is out of reach, we
would try to shrink the stack and then bringing it to reachable region.
However, even if it is out-of-reach for dup, it might still be in reach
for swap, so if it is safe to swap, we can do it directly.
@blishko

blishko commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

Style should be fixed now :)

@clonker
clonker merged commit bbbb423 into develop Mar 19, 2026
83 checks passed
@clonker
clonker deleted the ssa-cfg-shuffler-updates branch March 19, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants