http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54123
Bug #: 54123 Summary: inline functions not optimized as well as static inline Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: egg...@gnu.org Host: x86_64-unknown-linux-gnu Target: x86_64-unknown-linux-gnu Build: x86_64-unknown-linux-gnu Created attachment 27891 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27891 test case source code GCC does not optimize a function declared 'inline' as well as it optimizes the same function declared 'static inline'. There is no reason to optimize differently depending on whether an inline function is static. I discovered this problem when using GCC 4.7.1 to compile a test version of GNU Emacs that uses extern inline functions. This is a regression from GCC 4.6.3, which optimizes equally well in both cases. I enclose a small example of the problem. With GNU Emacs I found many more like this, and the size of the GNU Emacs text segment grew by 0.9% when compiled to use extern inline rather than static inline functions. To reproduce the problem, process the attached program xml-bug1.c as follows. (I'll also attach xml-static-inline.s and xml-inline.s.) gcc -std=gnu99 -O2 -S -DINLINE='static inline' -o xml-static-inline.s xml-bug1.c gcc -std=gnu99 -O2 -S -DINLINE='inline' -o xml-inline.s xml-bug1.c diff -u xml-static-inline.s xml-inline.s The diff output will read as follows. Notice that xml-inline.s contains an extra instruction 'cmpq Qnil(%rip), %r12' that xml-static-inline.s does not. The code is correct, but it's not optimized as well as it should be. --- xml-static-inline.s 2012-07-29 13:39:24.254184691 -0700 +++ xml-inline.s 2012-07-29 13:49:01.555043179 -0700 @@ -238,6 +238,7 @@ .L40: cmpq Qnil(%rip), %r12 je .L51 +.L69: movq %r12, %rax movq Qstringp(%rip), %rdi andl $7, %eax @@ -342,13 +343,8 @@ ret .p2align 4,,10 .p2align 3 -.L51: - .cfi_restore_state - movl $.LC1, %r13d - jmp .L41 - .p2align 4,,10 - .p2align 3 .L68: + .cfi_restore_state movq %r12, %rdi call xmlDocGetRootElement testq %rax, %rax @@ -363,8 +359,14 @@ movq %rsi, %rdi movq %rsi, 8(%rsp) call move_gap + cmpq Qnil(%rip), %r12 movq 8(%rsp), %rsi - jmp .L40 + jne .L69 + .p2align 4,,10 + .p2align 3 +.L51: + movl $.LC1, %r13d + jmp .L41 .L66: movq %rax, %rdx jmp .L45