From: grenie AT math DOT jussieu DOT fr Date: Sun, 3 Oct 1999 16:34:28 +0200 (MET DST) Message-Id: <199910031434.QAA10824@riemann.math.jussieu.fr> To: pgcc AT delorie DOT com X-URL: http://goof.com/pcg/questions.html X-Mailer: Lynx, Version 2.7 X-Personal_name: Loïc Grenié Subject: Optimization pug in pgcc-2.95.1 Cc: grenie AT math DOT jussieu DOT fr MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Reply-To: pgcc AT delorie DOT com 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.