public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16857] New: With -Os, ++ operation gets 3 instructions, not 1.
@ 2004-08-02 21:58 ralph at gcc dot gnu dot org
  2004-08-02 22:05 ` [Bug c/16857] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: ralph at gcc dot gnu dot org @ 2004-08-02 21:58 UTC (permalink / raw)
  To: gcc-bugs

Compiling the code below with -Os (i386 linux), the ++ gets compiled to 3
instructions, total 11 bytes.  It can be done with a single 6 byte instruction 
(as is done at other optimisation levels) & then save 3 more bytes due to better
register usage.

$ cat temp.c
static int bar;
static long baz;
  
int foo (_Bool x)
{
    int y;
    if (x) {
        ++baz;
        y = bar;
    }
    else {
        y = bar;
        ++baz;
    }
    return y;
}

$ gcc35 -S -o - -Os -fomit-frame-pointer  temp.c
...
foo:
        movl    baz, %eax
        movl    bar, %edx
        incl    %eax
        movl    %eax, baz
        movl    %edx, %eax
        ret
...
        .ident  "GCC: (GNU) 3.5.0 20040715 (Red Hat 3.5.0-0.7)"


Merging the 3 instructions for the ++ into 1, and removing the other unnecessary
movl would give:

foo:
        incl    baz
        movl    bar, %eax
        ret

-- 
           Summary: With -Os, ++ operation gets 3 instructions, not 1.
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ralph at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i386-redhat-linux


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


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

* [Bug c/16857] With -Os, ++ operation gets 3 instructions, not 1.
  2004-08-02 21:58 [Bug c/16857] New: With -Os, ++ operation gets 3 instructions, not 1 ralph at gcc dot gnu dot org
@ 2004-08-02 22:05 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-02 22:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-02 22:05 -------


*** This bug has been marked as a duplicate of 12395 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


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

end of thread, other threads:[~2004-08-02 22:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-02 21:58 [Bug c/16857] New: With -Os, ++ operation gets 3 instructions, not 1 ralph at gcc dot gnu dot org
2004-08-02 22:05 ` [Bug c/16857] " pinskia at gcc dot gnu dot 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).