Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dead load store analysis / optimisation #1535

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

ltratt
Copy link
Contributor

@ltratt ltratt commented Jan 7, 2025

This PR adds basic, but somewhat effective, dead load / store analysis optimisation (necessarily containing basic alias analysis). The main commit in this PR is 03c055b: it has, I hope, both adequate motivation in the commit message and sufficient tests and documentation in the code to show what's going on.

ltratt added 2 commits January 6, 2025 23:15
We need negative integers for `PtrAdd`. Note that other constructs
already reject negative integers appropriately, so this change can be
rather simple.
This commit adds a basic dead load / store optimisation. It is super
conservative: our alias analysis only does something useful when two
pointers derive from the same instruction and have a different offset.
In other words, we basically track `PtrAdd`s, since these guarantee that
our alias analysis is precise. We can clearly be somewhat more liberal,
but that will rapidly require deeper thought.

In somewhat more detail, the new `HeapValues` struct associates
`Address`es with values. Roughly speaking, each load adds more
information to this struct; stores will invalidate all previous loads /
stores unless we are entirely sure they don't alias; and barriers
invalidate all previous loads / stores.

Even though this is somewhat basic, it can still do some surprisingly
powerful optimisations. For example, give this trace IR (which is a
simplification of what we see in big_loop):

```
%0: ptr = param 0
%1: i8 = load %0
%2: i1 = eq %1, 3i8
guard true, %2, []
*%0 = 3i8
```

we determine that the store at instruction 5 is dead: it is writing back
a value to the heap (3i8) we know for sure (via a load and guard) is
already stored at that address. It is then turned into a tombstone.

The tests in `opt/mod.rs` give a wider view of what this can optimise.
The tests in `heapvalues.rs` give an indication of the detailed view of
our alias analysis.
@ptersilie ptersilie added this pull request to the merge queue Jan 7, 2025
Merged via the queue into ykjit:master with commit 07c3cae Jan 7, 2025
2 checks passed
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.

3 participants