This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug optimization/12395] New: Suboptimal code with global variables
- From: "steven at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Sep 2003 23:17:55 -0000
- Subject: [Bug optimization/12395] New: Suboptimal code with global variables
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12395
Summary: Suboptimal code with global variables
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: steven at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
Consider this tiny function:
void foo() {
extern int a;
if(++a) ++a;
}
It produces the following assembly with 3.4 (experimental) and 3.2 (Red Hat 9)
at -O2 and better:
.file "t.c"
.text
.globl foo
.type foo, @function
foo:
movl a, %eax
incl %eax
testl %eax, %eax
movl %eax, a
je .L1
incl %eax
movl %eax, a
.L1:
ret
.size foo, .-foo
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.5-tree-ssa 20030924 (merged 20030817)"
This is subobtimal. The optimal code should be:
foo:
addl $1,a
je .L1
addl $1,a
.L1:
ret