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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|NEW                         |ASSIGNED
                 CC|rguenther at suse dot de           |
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot 
gnu.org
            Summary|missed optimization:        |missed optimization:
                   |attribute ((pure)) could be |attribute ((pure)) with
                   |honored more often          |aggregate returns

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is rather that value-numbering is SSA based and thus

  D.2954 = globalStruct ();
  _10 = D.2954.val;
  D.2955 = globalStruct ();
  _12 = D.2955.val;

to CSE _12 to _10 we lookup the D.2955.val load and arrive at its def
D.2955 = globalStruct (); from where we can't look further.  FRE
has some tricks to look through aggregate copies but in this case
the aggregate copy source is a function call...

What we'd really need here is to re-write those aggregate temporaries
into SSA form (that also get's us aggregate copyprop for free).  We
can't have partial defs for those, of course, and we'd have to be careful
to not create overlapping life-ranges (because of cost issues - out-of-SSA
will make those "registers" memory again).

Eventually we could do this re-write into SSA form just for SCCVN ...

I don't see how we can easily extend the aggregate copy trick to cover
function calls.

Mine for now.  C testcase:

extern void link_error (void);

struct X { int i; };

struct X foo (void) __attribute__((pure));

int main()
{
  if (foo ().i != foo ().i)
    link_error ();
  return 0;
}

Reply via email to