[Bug ipa/89567] [missed-optimization] Should not be initializing unused struct parameter members

jamborm at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Mar 4 12:20:00 GMT 2019


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

Martin Jambor <jamborm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jamborm at gcc dot gnu.org

--- Comment #3 from Martin Jambor <jamborm at gcc dot gnu.org> ---
In the first excample, the interproceudral constant propagation pass
(IPA-CP) found that foo1 is so small that copying all of it might be
worth not passing the unused argument and so it does, that is why
you'll find function foo1 twice in the assembly.  This functionality
in the pass is there just "on the side" and it is not easy to make it
also work with aggegates, not even desireable (that is the job of a
different pass, see below).

Both examples are compiled better if you make foo1 and foo2 static.
In the latter case, you get exactly what you want, the structure is be
split and only the used part survives.  In the first example, you
don't get a clone emitted which you probably don't need.  Both of
these transformation are done by a pass called interprocedural scalar
replacement of aggregates (IPA-SRA), which specifically also aims to
remove unused arguments, but it never creates multiple clones.

If you cannot make these functions static, you need link-time
optimization (LTO, option -flto) because you need information about
one compilation unit to optimize others.  The current IPA-SRA cannot
unfortunately make use of it but I have a replacement for it that can,
hopefully it will be part of GCC 10.

I'm afraid you'd need to provide a strong real-world use-case to make
me investigate how to make IPA-SRA clone so you might not need static
and/or LTO because that would mean devising a cost/benefit
(size/speedup) heuristics and that is not easy.


More information about the Gcc-bugs mailing list