Repository navigation
Cranelift: A few perf improvements for the dead-store elimination pass - #13947
Merged
fitzgen merged 4 commits intoJul 23, 2026
Merged
Conversation
Never mixing information sourced from both the CFG and the func, which can get out of sync if the func is mutated after the CFG's construction.
The post-dominator tree is only consulted by dead-store elimination, and only for candidates whose two stores live in different blocks (because we can easily test post-domination without building a post-dominator tree when the two instructions are in the same block). The majority of functions have no such dead-store candidates, so building it eagerly for every function is a waste.
This commit replaces the parallel `observed_regions: EntitySet<AliasRegion>` with an `observed` boolean stored inline in each region's state. This removes a second heap allocation from every non-empty `LastStores` clone, which happens $O(blocks)$ times per function during the block-input fixpoint, and collapses `meet_from`'s per-region work into one pass.
The DSE alias-analysis `update` already has the instruction's opcode; pass it into `alias_regions_observed` instead of re-reading it from the DFG, since LLVM doesn't seem to dedupe it, and this code runs for every non-memory instruction on both the block-input fixpoint and the transform walk.
cfallin
approved these changes
Jul 23, 2026
cfallin
left a comment
Member
There was a problem hiding this comment.
LGTM -- thanks!
I was idly wondering whether we could be "even more lazy" wrt postdom: for example a backward walk from the maybe-overwriting store to see if every path meets the maybe-overwritten store before the entrypoint (avoiding revisits with a visit-set, etc). More or less like the Braun SSA construction algorithm, marching backward to find defs. That might be marginally faster when we just have a few queries (i.e. when we only really need a sparse subset of postdom info) but
- that's a whole new algorithm, and
- more importantly, I suspect your change here cuts out the majority of the cost anyway, since the computation is only at the end of a series of earlier gates
so no need to do that now. Just thought I'd mention in case it spawns any ideas later.
yagehu
referenced
this pull request
in yagehu/wasmtime-x
Jul 26, 2026
…s (#13947) * Make the post-dominator tree based only on the CFG Never mixing information sourced from both the CFG and the func, which can get out of sync if the func is mutated after the CFG's construction. * Cranelift: compute post-dominator tree lazily The post-dominator tree is only consulted by dead-store elimination, and only for candidates whose two stores live in different blocks (because we can easily test post-domination without building a post-dominator tree when the two instructions are in the same block). The majority of functions have no such dead-store candidates, so building it eagerly for every function is a waste. * Cranelift: fold DSE's observed-regions bitset into the regions map This commit replaces the parallel `observed_regions: EntitySet<AliasRegion>` with an `observed` boolean stored inline in each region's state. This removes a second heap allocation from every non-empty `LastStores` clone, which happens $O(blocks)$ times per function during the block-input fixpoint, and collapses `meet_from`'s per-region work into one pass. * Cranelift: avoid re-fetching opcode in alias_regions_observed The DSE alias-analysis `update` already has the instruction's opcode; pass it into `alias_regions_observed` instead of re-reading it from the DFG, since LLVM doesn't seem to dedupe it, and this code runs for every non-memory instruction on both the block-input fixpoint and the transform walk.
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.
Follow up to #13806 with a few perf improvements; see each commit. This, combined with my other perf PRs that have landed recently, recovers the hit to compilation times from introducing a dead-store elimination pass.