This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/16857] New: With -Os, ++ operation gets 3 instructions, not 1.
- From: "ralph at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Aug 2004 21:58:53 -0000
- Subject: [Bug c/16857] New: With -Os, ++ operation gets 3 instructions, not 1.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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