------- Comment #1 from rguenth at gcc dot gnu dot org 2009-11-29 12:54 ------- GCC has to weight code-size and compile-time increase against performance improvements when deciding on inlining functions. For the call in the loop GCC assumes it is more beneficial to do the inlining compared to the calls outside of the loop. With the calls outside of the loop the limits set for overall unit or function growth are reached. You can get diagnostics about this when you declare the function inline and use -Winline.
If you are sure that always inlining a function is beneficial you can declare it with __attribute__((always_inline)). You can also force all calls in a function to be inlined by declaring that function with __attribute__((flatten)). GCC 4.5 inlines all calls if switch_case is declared inline, 4.4 produces $ g++-4.4 -O3 t.C -Winline t.C: In function void slow(unsigned int*, const unsigned int*): t.C:36: warning: inlining failed in call to word_t switch_case(op_t, word_t, word_t, word_t) [with word_t = unsigned int]: call is unlikely and code size would grow t.C:67: warning: called from here t.C:36: warning: inlining failed in call to word_t switch_case(op_t, word_t, word_t, word_t) [with word_t = unsigned int]: call is unlikely and code size would grow t.C:79: warning: called from here As 4.5 works it's unlikely to be fixed unless some of the profile fixes also apply to 4.4 - Honza? -- rguenth at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hubicka at gcc dot gnu dot | |org Component|c++ |tree-optimization Keywords| |missed-optimization Known to work| |4.5.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42209