https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87008
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
struct A { double a, b; };
struct B : A {};
template<class T>void cp(T&a,T const&b){a=b;}
double f(B x){
B y; cp<A>(y,x);
B z; cp<A>(z,x);
return y.a - z.a;
}
This is not quite equivalent because RTL manages to optimize this case, but
gimple, with -Ofast, still gets the ugly:
ISRA.1 = MEM[(const struct A &)&x];
SR.9_9 = MEM[(struct A *)&ISRA.1];
ISRA.1 = MEM[(const struct A &)&x];
SR.8_10 = MEM[(struct A *)&ISRA.1];
_3 = SR.9_9 - SR.8_10;
return _3;
Writing cp<B> instead of cp<A> makes it work, and the main difference starts in
SRA. I expect (didn't check) this is another victim of r255510 .