Created attachment 19978 [details]
Code produced by lto1
Compiled with `-O2 -flto'
Created attachment 19979 [details]
Code compiled without `-flto'
Created attachment 19980 [details]
This is because
p = 0;
is not detected as dead store by tree DSE as in
p = 0;
r = *q;
p = (T *) t;
*q may load from p because with LTO TBAA rules for pointers have been
relaxed (for a reason but also in a somewhat simple manner). With
non-LTO void * and void ** have different alias-sets, with LTO they
do not (as especially mismatching void * and void ** is a very common
error that would lead to many spurious miscompiles with LTO).
Note that we really can't optimize this testcase without using TBAA
and by design we do not.