public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54123] New: inline functions not optimized as well as static inline
@ 2012-07-29 21:06 eggert at gnu dot org
  2012-07-29 21:07 ` [Bug c/54123] " eggert at gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: eggert at gnu dot org @ 2012-07-29 21:06 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: eggert@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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/54123] inline functions not optimized as well as static inline
  2012-07-29 21:06 [Bug c/54123] New: inline functions not optimized as well as static inline eggert at gnu dot org
@ 2012-07-29 21:07 ` eggert at gnu dot org
  2012-07-29 21:08 ` eggert at gnu dot org
  2012-07-30  9:05 ` [Bug middle-end/54123] " rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: eggert at gnu dot org @ 2012-07-29 21:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54123

--- Comment #1 from eggert at gnu dot org 2012-07-29 21:07:26 UTC ---
Created attachment 27892
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27892
test case compiled with -DINLINE='static inline'


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/54123] inline functions not optimized as well as static inline
  2012-07-29 21:06 [Bug c/54123] New: inline functions not optimized as well as static inline eggert at gnu dot org
  2012-07-29 21:07 ` [Bug c/54123] " eggert at gnu dot org
@ 2012-07-29 21:08 ` eggert at gnu dot org
  2012-07-30  9:05 ` [Bug middle-end/54123] " rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: eggert at gnu dot org @ 2012-07-29 21:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54123

--- Comment #2 from eggert at gnu dot org 2012-07-29 21:08:17 UTC ---
Created attachment 27893
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27893
test case compiled with -DINLINE='inline'


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/54123] inline functions not optimized as well as static inline
  2012-07-29 21:06 [Bug c/54123] New: inline functions not optimized as well as static inline eggert at gnu dot org
  2012-07-29 21:07 ` [Bug c/54123] " eggert at gnu dot org
  2012-07-29 21:08 ` eggert at gnu dot org
@ 2012-07-30  9:05 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-30  9:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54123

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-07-30
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-30 09:05:25 UTC ---
Confirmed.  inline and static inline should be the same with C99.

Honza - I suppose inlining static functions called once may be the
reason this doesn't work with plain 'inline'.  I guess we need a better
predicate here?  inline functions called once whose bodies can be
removed?


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-30  9:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-29 21:06 [Bug c/54123] New: inline functions not optimized as well as static inline eggert at gnu dot org
2012-07-29 21:07 ` [Bug c/54123] " eggert at gnu dot org
2012-07-29 21:08 ` eggert at gnu dot org
2012-07-30  9:05 ` [Bug middle-end/54123] " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).