This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/16857] New: With -Os, ++ operation gets 3 instructions, not 1.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]