Bug 81980 - GCC inline limit is very bad
Summary: GCC inline limit is very bad
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: gcc
Version: 1.0
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-01-15 23:20 UTC by Luca Barbieri
Modified: 2007-04-18 16:50 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2004-10-03 11:59:16 UTC
Embargoed:


Attachments (Terms of Use)
Sample code (484 bytes, text/plain)
2003-01-15 23:26 UTC, Luca Barbieri
no flags Details

Description Luca Barbieri 2003-01-15 23:20:23 UTC
Description of Problem:
GCC apparently disregards the programmer use of the "inline" keyword when the
function is larger than a certain threshold, potentially causing very poor code
generation.

Furthermore it appears to do so based on the size of the function rather than
the size of the optimized code that would be generated by inlining it, which
makes the problem much worse.

In particular some functions (e.g. Linux memcpy and friends) check whether
parameters are constant and if so do a long list of checks on the parameters,
sure that they will be optimized away: GCC screws this up horribly and
transforms a clever programmer optimization in a huge slowdown.

There also functions that are very long and cannot be splitted in separate
"physical" functions for performance reasons, but are instead splitted in, maybe
very long, inline functions that are used once: GCC also screws this up horribly.


IMHO this "feature" should be removed, and GCC should always honor the
programmer's choice, which he must make correctly anyway since other compilers
might not correct it.

If that is not possible, the limit should at least be increased.


The problem can be worked around using this code:
#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2))
#if !defined(__cplusplus) && defined(__OPTIMIZE__)
#define inline inline __attribute__((always_inline))
#endif
#endif


Version-Release number of selected component (if applicable):
gcc-3.2.1-2

How Reproducible:
Every time.

Steps to Reproduce:
1. Compile the attached code with "-O2 -S" for x86code; then add the
"-finline-limit=1000000" option and compare the two assembly listings.

-or-

1. Compile Linux for x86 with no special inline limit settings and do an `nm
vmlinux|grep __constant`. These functions should have been inlined.

Comment 1 Luca Barbieri 2003-01-15 23:26:27 UTC
Created attachment 89396 [details]
Sample code

Comment 2 Richard Henderson 2004-10-03 11:59:16 UTC
Inline heuristics rewritten for gcc 3.4.  Things are significantly
better there.  Debugging output (-dU) shows

Considering generic_fls with 38 insns
 Estimated growth is -10 insns.
 Inlined into test which now has 51 insns.
 Inlined 1 times for a net change of -10 insns.



Note You need to log in before you can comment on or make changes to this bug.