This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Suboptimal code (gcc 2.95.1, i386-unknown-openbsd)
- To: egcs@egcs.cygnus.com
- Subject: Suboptimal code (gcc 2.95.1, i386-unknown-openbsd)
- From: Marc Espie <espie@schutzenberger.liafa.jussieu.fr>
- Date: Thu, 9 Sep 1999 15:49:10 +0200
- Reply-To: Marc.Espie@liafa.jussieu.fr
Fiddling with optimization...
#define VAL 10
void f(char *s)
{
char *u = s;
while (u < s+VAL)
*u++='a';
}
Using -O3, I get:
.file "a.c"
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 2,0x90
.globl _f
.type _f , @function
_f:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
leal 10(%eax),%edx
cmpl %edx,%eax
jae L4
.align 2,0x90
L5:
movb $97,(%eax)
incl %eax
cmpl %edx,%eax
jb L5
L4:
leave
ret
.size _f , . - _f
Notice the comparison and jump to L4 that will never occur.
Is gcc required to assume that pointer arithmetic may wrap around,
or is it just some optimization it misses ?