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

--- Comment #35 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Namniav from comment #34)
> I'd like to provide a more subtle example:
> 
> #include <stdio.h>
> #include <stdint.h>
> 
> int main() {    
>     int a = -1;
>     int b = -1;
>     uintptr_t ia = (uintptr_t)&a;
>     uintptr_t ib = (uintptr_t)(&b + 1);
>     if (ia == ib) {
>         *(int*)(ia == ib ? ia : ib) = 42;
>         printf("%d\n", a);
>     }
>     return 0;
> }
> 
> It prints -1 compiled by gcc -O1 (https://godbolt.org/z/ecf4Kjc16).

It's "subtle" only in a way showing that we simplify ia == ib ? ia : ib
to ib and that we simplify (int *)(uintptr_t)(&b + 1) to (&b + 1).
Not doing the latter wouldn't help as points-to analysis also tracks
provenance through integers.  I'm quite sure we do the simplification
even iff ia and ib were pointers.

The example shows we not only perform copy substitution through equivalences
during optimization passes but also in expression folding.

Reply via email to