I expect "one" not to be emitted when compiling this with -O3: === cut here === static inline unsigned long one(void) { return 1; } static inline unsigned long call(unsigned long (*fn)(void)) { return fn(); } int test_call(void) { return call(one); } === cut here === .file "foo.c" .text .p2align 4,,15 .type one, @function one: pushl %ebp movl $1, %eax movl %esp, %ebp popl %ebp ret .size one, .-one .p2align 4,,15 .globl test_call .type test_call, @function test_call: pushl %ebp movl %esp, %ebp popl %ebp jmp one .size test_call, .-test_call .ident "GCC: (GNU) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)" .section .note.GNU-stack,"",@progbits === cut here ===
The lack of this optimization means that it's inefficient to write generic routines (eg. see include/linux/rbtree.h in the Linux sources). Thanks, Rusty. -- Summary: Missed optimization with function ptrs even when inline Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rusty at rustcorp dot com dot au GCC build triplet: i486-linux-gnu GCC host triplet: i486-linux-gnu GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32751