public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* inliner in gcc-3.1
@ 2002-04-24  4:37 Kurt Garloff
  2002-04-24 16:31 ` Daniel Berlin
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Kurt Garloff @ 2002-04-24  4:37 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 3991 bytes --]

Hi,

I was browsing the gcc ML archives (I'm not subscribed) and found
that the inliner may still not be tuned optimally in gcc-3.1.
http://gcc.gnu.org/ml/gcc/2002-04/msg01168.html
The problem seems to be mainly with C++ functions, where you want small
accessor functions to be reliably inlined and where the inliner heuristics
sometimes fails.

I've done some work on this before and got a patch of mine merged (between
3.0.1 and 3.0.3) that fixed the heuristics which lead to ridicolous compile
time resource requirements (gcc-3.0.0) resp. ridicolous performance
(gcc-3.0.1) according to my own and Gerard Pfeifer's benchmarks. See
http://www.garloff.de/kurt/freesoft/gcc/

To give a very short summary: Before gcc-3.0, some accounting for the
inlining was introduced to prevent huge functions to be inlined due to
recursive inlining. Unfortunately, inlining starts at the root
of the call tree, so in the end, the leaves would not be inlined any more 
despite being the most performance critical very often.
This was fixed with a simplistic patch that does just reduce the acceptable
size for inlining for single functions by a factor of two and -- after
reaching the (full) limit by recursion -- cut it further down by another
factor of two. (This is what I refer to as v1 of my inliner patch.)
That patch fixed the most serious problems and got merged.

Later I did some more fine tuning (patches v2,v3) and did use some linear
function to limit acceptable inlinable sizes for single functions. This 
seems somewhat saner. It did only give slightly better results in
benchmarks.

I'd like to add a few comments again:
* I was expecting to find the AST inliner in gcc-3.1.
  I do believe it's more sane starting to inline from the leaves of
  a call tree than from the root, so I would have expected that approach
  (if tuned well) to win all benchmarks.
* I have adapted by inliner patch (v3) to 3.1 (CVS 2002-04-23)
  and it still works ...
  I do believe it's somewhat saner than v1, but the benefits are
  actually small. (up to 3% in some benchmarks, 0 in others, no
  pessimizations found).

It would be nice if C++ people would try it to see whether it helps them.
I would certainly appreciate if it gets merged. (Yes, the FSF has a signed
copyright assignment ...)

I made another patch for 3.0.1 and adapted it to 3.1, which is probably much
more interesting: The -O3 (-finline-functions) fix.

In the code I use, I put the inline keyword at all places where it was
obvious to my eyes that inlining was a good idea. When I compile that code
with -O3 (aka -finline-functions), performance drops by 5--10%.

The reason is that comparably large functions get automatically inlined, so
the recursive inline limit is hit earlier, and the important leaf functions
sometimes do not get inlined any more. The problem is that all functions
are treated as if they were declared inline, so the keyword gets completely
ignored. I changed this and allow automatically inlined functions only half
the size of functions declared inline by the programmer.
This reduced the performance drop incurred by -finline-functions to 0.5--1.5%.

It would be nice if this patch 
http://www.garloff.de/kurt/freesoft/gcc/gcc310-inline-func-acct-v1.diff
would be tested by more people and integrated into 3.1.
I'd like to know whether it will help to get the SpecCPU/FP peak value above
the base for more benchmarks.
It probably needs some review by people who know gcc code better than I,
so I would certainly appreciate if somebody picks up the patch and
polishes it ... (and e.g. ports it to other languages than C and C++).

Regards,
-- 
Kurt Garloff                   <kurt@garloff.de>         [Eindhoven, NL]
Physics: Plasma simulations  <K.Garloff@Phys.TUE.NL>  [TU Eindhoven, NL]
Linux: SCSI, Security          <garloff@suse.de>    [SuSE Nuernberg, DE]
 (See mail header or public key servers for PGP2 and GPG public keys.)

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2002-04-30 14:49 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-24  4:37 inliner in gcc-3.1 Kurt Garloff
2002-04-24 16:31 ` Daniel Berlin
2002-04-25 15:06   ` Kurt Garloff
2002-04-25 18:25     ` Daniel Berlin
2002-04-25  0:21 ` Gerald Pfeifer
2002-04-25  0:48   ` Richard Henderson
2002-04-25 15:51   ` Kurt Garloff
2002-04-25  9:41 ` Gerald Pfeifer
2002-04-25 15:30   ` Kurt Garloff
2002-04-26  4:19     ` Gerald Pfeifer
2002-04-26  8:20       ` Kurt Garloff
2002-04-27  9:49   ` Kurt Garloff
2002-04-30  7:49     ` Gerald Pfeifer
2002-04-30  7:59       ` Daniel Berlin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).