- To: submit at bugs dot debian dot org
- Subject: Bug#67206: gcc: optimiser could be improved
- From: <herbert at gondor dot apana dot org dot au>
- Date: Fri, 14 Jul 2000 13:45:24 +1000
- Reply-To: <herbert at gondor dot apana dot org dot au>, 67206 at bugs dot debian dot org
- Resent-CC: Debian GCC maintainers <gcc at packages dot debian dot org>
Package: gcc
Version: 1:2.95.2-14
Severity: wishlist
Here are a couple of things I noticed for i386 while trying to fix alpha
unaligned traps.
1. Combining neighbouring instructions:
-- source --
#include <time.h>
#include <sys/time.h>
char *p;
void b(struct timeval);
void a() {
struct timeval k;
#if 0
memcpy(&k, p, sizeof(k));
b(k);
#else
b(*(struct timeval *)p);
#endif
}
-- assembly (gcc -O2 -S) --
.file "b.c"
.version "01.01"
gcc2_compiled.:
.comm p,4,4
.text
.align 4
.globl a
.type a,@function
a:
pushl %ebp
movl %esp,%ebp
subl $8,%esp
addl $-8,%esp
movl p,%eax
movl (%eax),%edx
movl 4(%eax),%ecx
pushl %ecx
pushl %edx
call b
leave
ret
.Lfe1:
.size a,.Lfe1-a
.ident "GCC: (GNU) 2.95.2 20000220 (Debian GNU/Linux)"
-- end --
The subl and the addl can be combined.
2. Removing unused local variables.
-- source --
#include <time.h>
#include <sys/time.h>
char *p;
void b(struct timeval);
void a() {
struct timeval k;
#if 1
memcpy(&k, p, sizeof(k));
b(k);
#else
b(*(struct timeval *)p);
#endif
}
-- assembly (gcc -O2 -S) --
.file "a.c"
.version "01.01"
gcc2_compiled.:
.text
.align 4
.globl a
.type a,@function
a:
pushl %ebp
movl %esp,%ebp
subl $24,%esp
movl p,%eax
movl (%eax),%edx
movl %edx,-8(%ebp)
movl 4(%eax),%eax
movl %eax,-4(%ebp)
addl $-8,%esp
movl -8(%ebp),%eax
movl -4(%ebp),%edx
pushl %edx
pushl %eax
call b
leave
ret
.Lfe1:
.size a,.Lfe1-a
.comm p,4,4
.ident "GCC: (GNU) 2.95.2 20000220 (Debian GNU/Linux)"
-- end --
I'm not sure how hard this is to do, but storing k and retrieving it again
seems to be a waste.
-- System Information
Debian Release: 2.2
Kernel Version: Linux gondor 2.2.12 #2 Sat Sep 18 12:11:40 EST 1999 i586 unknown
Versions of the packages gcc depends on:
ii binutils 2.10.0.9-4 The GNU assembler, linker and binary utilities.
ii cpp 2.95.2-14 The GNU C preprocessor.
ii libc6 2.1.3-10 GNU C Library: Shared libraries and Timezone data