Skip to content

[LocalCSE] Consider size-2 expressions when shrinking - #9161

Open
artemkulyk wants to merge 1 commit into
WebAssembly:mainfrom
artemkulyk:local-cse-size-2
Open

artemkulyk wants to merge 1 commit into
WebAssembly:mainfrom
artemkulyk:local-cse-size-2

Conversation

@artemkulyk

Copy link
Copy Markdown

Under -Os and -Oz, LocalCSE required an expression of IR size 3 before
keeping a reused value in a local. A size-2 expression reused twice can
still pay off: we drop one copy and add a local.set and a local.get.
Allow size 2 in shrink modes.

Skip it when the function has no locals at all, where coalesce-locals
cannot merge the new local away and a single reuse would grow the output.

Saves 22 KB on a 1650 module corpus, mostly in large functions that repeat
small expressions such as (i32.load (local.get $p)).

@artemkulyk
artemkulyk requested a review from a team as a code owner September 26, 2026 13:05
@artemkulyk
artemkulyk requested review from aheejin and removed request for a team September 26, 2026 13:05
Under -Os and -Oz, LocalCSE required an expression of IR size 3 before
keeping a reused value in a local. A size-2 expression reused twice can
still pay off: we drop one copy and add a local.set and a local.get.
Allow size 2 in shrink modes.

Skip it when the function has no locals at all, where coalesce-locals
cannot merge the new local away and a single reuse would grow the output.

Saves 22 KB on a 1650 module corpus, mostly in large functions that repeat
small expressions such as (i32.load (local.get $p)).

This branch has not been deployed

No deployments
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.

1 participant