https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88854

--- Comment #5 from rguenther at suse dot de <rguenther at suse dot de> ---
On Tue, 15 Jan 2019, kretz at kde dot org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88854
> 
> --- Comment #4 from Matthias Kretz <kretz at kde dot org> ---
> Another test case, which the patch doesn't optimize:
> 
> short f(int *a, short *b) {
>     short y = *b; // 1
>     int x = *a;   // 2
>     *b = 1;
>     *a = x;
>     return y;
> }
> 
> The loads in 1+2 are either UB or a and b must not alias. Consequently the
> store to b won't change a and the store to a is dead.
> 
> General rule:
> Given two pointers a and b of different type, where b is not a pointer to 
> char,
> unsigned char, or std::byte, if
> - a load of a is followed by a load of b, or
> - a store to a is followed by a load of b
> then a and b are guaranteed to point to different addresses.

Yeah, we do not perform this kind of "flow-sensitive" TBAA.  So
when trying to DSE *a = x; we only look at

     int x = *a;
     *b = 1;
     *a = x;

and do not consider the earlier load from *b at all because it is
not on the path from the load making the store possibly redundant.

Reply via email to