This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/16856] New: Missed optimisation opportunity with -O2
- 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:38:10 -0000
- Subject: [Bug c/16856] New: Missed optimisation opportunity with -O2
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following code is not optimised optimally with -O2. The two branches of the
conditional have the same effect, so the conditional can be removed entirely.
The conditional is removed with -Os, so gcc is capable of carrying out the
optimisation; it just isn't happening at -O2.
$ 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 -O2 -fomit-frame-pointer -o temp-O2.s temp.c
$ cat temp-O2.s
...
foo:
cmpb $0, 4(%esp)
je .L2
incl baz
movl bar, %eax
ret
.p2align 2,,3
.L2:
movl bar, %eax
incl baz
ret
...
.ident "GCC: (GNU) 3.5.0 20040715 (Red Hat 3.5.0-0.7)"
--
Summary: Missed optimisation opportunity with -O2
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
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16856