Skip to content

Implement idempotent-store elimination#13251

Merged
fitzgen merged 2 commits intobytecodealliance:mainfrom
fitzgen:wasmtime-idempotent-store-elimination
May 1, 2026
Merged

Implement idempotent-store elimination#13251
fitzgen merged 2 commits intobytecodealliance:mainfrom
fitzgen:wasmtime-idempotent-store-elimination

Conversation

@fitzgen
Copy link
Copy Markdown
Member

@fitzgen fitzgen commented May 1, 2026

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 #4167

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
@fitzgen fitzgen requested review from a team as code owners May 1, 2026 21:41
@fitzgen fitzgen requested review from alexcrichton, cfallin and uweigand and removed request for a team, alexcrichton and uweigand May 1, 2026 21:41
Copy link
Copy Markdown
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

LGTM with minor tweaks -- thanks!

Comment thread cranelift/codegen/src/egraph/mod.rs Outdated
Comment thread cranelift/codegen/src/alias_analysis.rs
Comment thread cranelift/codegen/src/alias_analysis.rs
Comment thread cranelift/filetests/filetests/alias/idempotent-store.clif Outdated
@fitzgen fitzgen enabled auto-merge May 1, 2026 22:08
@fitzgen fitzgen added this pull request to the merge queue May 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 1, 2026
@fitzgen fitzgen added this pull request to the merge queue May 1, 2026
Merged via the queue into bytecodealliance:main with commit 79a81e5 May 1, 2026
48 checks passed
@fitzgen fitzgen deleted the wasmtime-idempotent-store-elimination branch May 1, 2026 23:53
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.

2 participants