Cranelift: extend alias analysis to eliminate dead stores#13806
Conversation
|
This is a speed up for our compile-time builtins benchmarks, as mentioned here: On a PCA-based subset of Sightglass:
Sightglass resultsI can look into speeding things up a bit more, but we should probably discuss this at the next Cranelift meeting. |
|
I'm going to move this to being reviewed by @cfallin who I know is on PTO right now but I think will have sufficiently more context about this that he'll do a much better job than I |
|
(happy to do so; logistical note that I'm out on PTO this week and next, then traveling-for-work the following week, so I can't guarantee I'll get to this before Mon Jul 20) |
cfallin
left a comment
There was a problem hiding this comment.
This looks correct to me -- thanks for the really careful work here!
A few points below but nothing fundamental.
|
Regarding the compilation hit that this PR implies: I have a handful of optimizations that I will start making PRs for that recover that compile time in other areas. |
|
One point to track as a followup further improvement, possibly: if we have a mode (enforced by Wasmtime API) that ensures that the |
This commit adds an "observed?" bit to every alias region in the alias analysis's `LastStores` data. Loads from a region set the bit, as do instructions that act as memory fences, like calls. When we see a store to a region that hasn't been observed, and the store is to the same memory location as the last store to that region, then the last store is dead and can be removed. This integrates with alias analysis's existing single forwards pass that is fused with the egraph pass; it doesn't require additional passes or iterations. However, because it is a single pass and not a fixed point, updates do not cascade, and removing a dead store does not then recompute `LastStores` and reveal that (for example) the dead store's killer is an idempotent store which could also be removed. See the new `check-unset-reset-flag.clif` filetest, which roughly reflects what component-model fused adapters do with the `MAY_LEAVE` flag, for an example of this behavior. Fixes bytecodealliance#4167
e8f2a1f to
0448d1c
Compare
|
We talked about this a bit at today's Cranelift meeting and the conclusion was to go ahead and merge; I'll also have a couple more perf follow ups soon. |
This commit adds an "observed?" bit to every alias region in the alias analysis's
LastStoresdata. Loads from a region set the bit, as do instructions that act as memory fences, like calls. When we see a store to a region that hasn't been observed, and the store is to the same memory location as the last store to that region, then the last store is dead and can be removed. This integrates with alias analysis's existing single forwards pass that is fused with the egraph pass; it doesn't require additional passes or iterations. However, because it is a single pass and not a fixed point, updates do not cascade, and removing a dead store does not then recomputeLastStoresand reveal that (for example) the dead store's killer is an idempotent store which could also be removed. See the newcheck-unset-reset-flag.cliffiletest, which roughly reflects what component-model fused adapters do with theMAY_LEAVEflag, for an example of this behavior.Fixes #4167