This is the mail archive of the gcc@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]

suggestion to improve optimization


[this suggestions was submitted on the Debian BTS; please CC
 67206@bugs.debian.org on replies.]

Same behaviour in 20000720 CVS.



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



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