This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization, inline functions
- From: "Lawrence Crowl" <crowl at google dot com>
- To: "Lee, Newbie" <utmw0 at hanmail dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 7 Jul 2008 16:26:18 -0700
- Subject: Re: Optimization, inline functions
- References: <18273137.post@talk.nabble.com>
On 7/3/08, Lee, Newbie <utmw0@hanmail.net> wrote:
> I thought function inlining is simple and easy thing.
Inlining didn't become common until the mid 1980s. If it were easy,
it would have happened earlier. :-)
> But I read that gcc doesn't make function inline without
> optimization flag, and function inlining is the last thing to do
> when gcc optimize something.
>
> So I compiled a cpp file with -S and -O1, -O2, -O3 flags.
> Document says that only -O3 turns on function inlining, but with
> -O2, gcc also eliminated function calls. The result was better
> than I expected.
Part of the confusion may come from the kind of inlining.
- Inlining of functions that are declared inline.
- Inlining of functions that are not declared inline.
The latter generally occurs only at higher optimization levels.
> But I am confusing.
>
> 0. Does 'gcc -O2' make functions inline?
If you declared them inline, yes.
> 1. Is function inlining is dangerous?
Yes, but only when used with linker interposition. Most functions
are unaffected by inlining.
> 2. Is 'gcc -O3 ' safe? (I heard -O2 is recommended)
Higher levels of optimization will cause more of your bugs to
activate. So, it all depends on what bugs you have in your code.
> and any advice about this will help me.
Write bug-free code. :-)
Failing that, lots of tests help.
--
Lawrence Crowl