This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 3.2.1 optimizer degradation (strlen, -O2)
I think you forgot or lost the -O2 option. The 3.2.1 code you posted is what
I got when I don't use any -O? option at all. With -O2, optimized for
Pentium, I got the following code:
strlen.c:
_strlen:
pushl %ebp
xorl %eax, %eax
movl %esp, %ebp
movl 8(%ebp), %edx
testl %edx, %edx
je L1
movl %edx, %eax
cmpb $0, (%edx)
je L9
.p2align 4,,7
L7:
incl %eax
cmpb $0, (%eax)
jne L7
L9:
subl %edx, %eax
L1:
popl %ebp
ret
strlen2.c:
_strlen:
pushl %ebp
xorl %eax, %eax
movl %esp, %ebp
movl 8(%ebp), %ecx
movl %ecx, %edx
testl %ecx, %ecx
je L1
.p2align 4,,7
L3:
movb (%edx), %al
incl %edx
testb %al, %al
jne L3
subl %ecx, %edx
leal -1(%edx), %eax
L1:
popl %ebp
ret
Marcel
"Leonid Pauzner" <uue@pauzner.dnttm.ru> wrote in message
2.7.9.SBA.H8K8TU@pauzner.dnttm.ru">news:2.7.9.SBA.H8K8TU@pauzner.dnttm.ru...
>
> Sure, there is a "call _strlen" line in the assembler code,
> and I made the test program by calling
> "gcc -o strlen.exe main.o strlen.o"
>
> This is a DJGPP environment.
>
> The key point in my original posting was the certain simple loop
> which happens to be optimized better with the old version of the compiler.
> Generated assembler attached.
>