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.