C++ Logo


Advanced search

[std-proposals] P2815 breaks all provenance-related optimizations

From: connor horman <chorman64_at_[hidden]>
Date: Tue, 21 Feb 2023 21:53:04 -0500
I just learned of P2815, and I do not know of another place I can respond
to it, so I'm going to answer here.

In my opinion, the proposal in question eliminates all provenance based
alias analysis, used to eliminate memory accesses when unanalyzed code is

Consider the following example code:

int foo(int* p){
     int i;
     i = 0;
     *p = 1;
     return i;

(Where the optimizer is unable to analyze `opaque_operation`
In current compilers, this can be optimized to calling `opaque_operation`,
writing `1` to `p`, and then returning `0`. Under the proposal, however,
`opaque_operation` could observe that `&i` and `p` have the same *value
representation*, which means that they must be equal (it may do so with
defined behaviour in all executions, for example, by terminating if they
are bytewise unequal). Thus the write to `p` may modify the value of `i`.
This would make the transformation to:

int foo(int* p){
    *p = 1;
    return 0;

invalid under the proposal.

In my opinion, this extends to basically all similar transformations, which
is the majority of provenance-based alias analysis.

Further, it means that a non-volatile read as a character type (which may
then be used to test the value representation) cannot be optimized away
when applied to an unknown object (because that object may contain a
pointer). In particular, a discarded `memcmp` is now able to alter the
behaviour of the program, despite previously being able to be elided
because the function is pure.

Link to the proposal in question:

Received on 2023-02-22 02:53:18