Mail Archives: pgcc/1999/10/03/12:40:50
Hello,
I've found a bug in pgcc-2.95.1. When I compile the following program:
func(void)
{
int tab[512], i;
for (i = 0; i < 511; i++)
tab[i+1] = tab[i];
}
with gcc -O4 -mpentium I obtain code which is incorrect. Namely, at the end
of the loop the pointer &tab[i] and the variable i are incremented 512
times two much. Here is the code I obtain:
func:
pushl %ebp
movl %esp,%ebp
subl $2064,%esp
movl $-511,%ecx
pushl %esi
pushl %ebx
leal -2048(%ebp),%edx
movl $4,%esi
xorl %ebx,%ebx
.align 4
.L6:
movl (%ebx,%edx),%eax
movl %eax,(%esi,%edx)
addl $4,%esi
addl $2048,%ebx
addl $512,%ecx
jne .L6
popl %ebx
popl %esi
movl %ebp,%esp
popl %ebp
ret
the addl $2048,%ebx should be a addl $4,%ebx and the addl $512,%ecx should
be addl $1,%ecx. I've tried to isolate the bug in the sources, but I've
failed...
If the correction is small, I'd like to have it as soon as it's been made
by email if possible.
Loïc
PS: another idea for optimization: the following code would be better:
func:
pushl %ebp
movl %esp,%ebp
subl $2064,%esp
movl $-511,%ecx
pushl %esi
pushl %ebx
leal -2048(%ebp),%edx
xorl %ebx,%ebx
.align 4
.L6:
movl (%ebx,%edx),%eax
addl $4,%ebx
movl %eax,(%esi,%edx)
addl $4,%esi
addl $1,%ecx
jne .L6
popl %ebx
popl %esi
movl %ebp,%esp
popl %ebp
ret
and %esi could be eliminated by using only %ebx, but I'm not sure that would
be really interesting in this setup.
- Raw text -