[LocalCSE] Consider size-2 expressions when shrinking - #9161
Open
artemkulyk wants to merge 1 commit into
Open
artemkulyk wants to merge 1 commit into
artemkulyk wants to merge 1 commit into
Conversation
artemkulyk
force-pushed
the
local-cse-size-2
branch
from
September 26, 2026 13:06
cba1ad2 to
67cf9a1
Compare
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
force-pushed
the
local-cse-size-2
branch
from
September 26, 2026 13:25
67cf9a1 to
e348f57
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)).