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

CSE: remember the abstract pointers in Load equations #518

Merged
merged 3 commits into from
Aug 19, 2024
Merged

Conversation

xavierleroy
Copy link
Contributor

CSE uses non-aliasing information provided by value analysis to reuse the result of a previous load after a store, provided the load and the store do not alias.

In the current implementation of CSE, the abstract pointer associated with the previous load is not stored in the CSE-inferred equations, but is recomputed at the point of the store just before calling the non-aliasing test pdisjoint. This can lead to loss of precision, as in the following example:

    x1 <- addrglobal "x"
    y <- load x1
    y1 <- addrglobal "y"
    store(y1, ...)
    x2 <- addrglobal "x"
    z <- load x2

At the point of the store instruction, we no longer know that the value of x1 is a pointer into the "x" global. (That's because value analysis forgets the abstract values of pseudoregisters when they become dead, so as to avoid memory blowup on large codes.) Hence, CSE doesn't know that the "store" and the first "load" do not interfere, and forgets the equation describing the first "load". Consequently, the second "load" cannot be replaced by z <- y.

This PR addresses this issue by storing in Load equations the abstract pointers describing the location of the read. These abstract pointers are determined at the time when Load equations are generated and when full abstract value information is available. This produces better code for examples such as the one above, and could also reduce compilation times for CSE, as some recomputations of abstract pointers are avoided.

The two abstract pointers being compared can come from different block
classifications, as long as the two classifications agree on globals
and on the stack pointer.
@xavierleroy
Copy link
Contributor Author

The CI failure on PPC appears unrelated, it occurs also on master but not on my other CI, which uses different versions of qemu. To be debugged.

Copy link
Contributor Author

@xavierleroy xavierleroy left a comment

Choose a reason for hiding this comment

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

Testing at AbsInt shows good results. Merging.

backend/CSEdomain.v Outdated Show resolved Hide resolved
@@ -77,7 +77,7 @@ Fixpoint find_valnum_rhs (r: rhs) (eqs: list equation)
match eqs with
| nil => None
| Eq v str r' :: eqs1 =>
if str && eq_rhs r r' then Some v else find_valnum_rhs r eqs1
if str && compat_rhs r r' then Some v else find_valnum_rhs r eqs1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could probably take the glb (intersection) of the abstract pointers in r and r', as it seems that both abstract pointers are valid. But I'm not expecting any significant precision gain from that, so let's keep it for future work.

This is simpler than recomputing abstract pointers in the `kill_loads`
functions.  This is also more precise, as some results of value
analysis may no longer be available at the PC where a `kill_loads`
function is invoked.
@xavierleroy xavierleroy merged commit 9e47293 into master Aug 19, 2024
1 of 7 checks passed
@xavierleroy xavierleroy deleted the cse-alias branch August 19, 2024 07:23
@monniaux
Copy link
Contributor

@xavierleroy FYI We are also experiencing problems with qemu-ppc 7.2.11 in our CI (render produces an illegal instruction in it), which happens neither on qemu-ppc 4.2.1 nor on 9.02.

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