Implement idempotent-store elimination#13251
Merged
fitzgen merged 2 commits intobytecodealliance:mainfrom May 1, 2026
Merged
Conversation
This is a very particular subset of "dead-store elimination" that we can do without extending the static analysis at all (e.g. we do *not* need to show that the target store is post-dominated by another store to the same location in this case). The key idea is this: if our existing analysis tells us that a memory location L is currently known to contain the value `v0` (such that we could do redundant-load elimination by removing `v8 = load L` and making `v8` an alias of `v0`) then we can remove `store v0, L` because memory location `L` already contains that value. We also do not need to worry about traps because if `L` already has a known-value, that must have been from a load or store to `L` that dominates our idempotent `store` instruction, and if this idempotent `store` would trap, then the original load/store to `L` would have already trapped first. This does not result in any statistically significant differences in Sightglass. cc bytecodealliance#4167
cfallin
approved these changes
May 1, 2026
Member
cfallin
left a comment
There was a problem hiding this comment.
LGTM with minor tweaks -- thanks!
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.
This is a very particular subset of "dead-store elimination" that we can do without extending the static analysis at all (e.g. we do not need to show that the target store is post-dominated by another store to the same location in this case). The key idea is this: if our existing analysis tells us that a memory location L is currently known to contain the value
v0(such that we could do redundant-load elimination by removingv8 = load Land makingv8an alias ofv0) then we can removestore v0, Lbecause memory locationLalready contains that value. We also do not need to worry about traps because ifLalready has a known-value, that must have been from a load or store toLthat dominates our idempotentstoreinstruction, and if this idempotentstorewould trap, then the original load/store toLwould have already trapped first.This does not result in any statistically significant differences in Sightglass.
cc #4167