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

--- Comment #7 from Martin Jambor <jamborm at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #1)
> 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 .

Indeed, with the proof-of-concept patch from PR 85762, this gets optimized
into:

  <bb 2> [local count: 1073741824]:
  SR.7_2 = MEM[(const struct A &)&x];
  _3 = SR.7_2 - SR.7_2;
  return _3;

with -O2 and to retrn 0 with -Ofast.

Reply via email to