avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] About loop (mis-)optimizations


From: J Wunsch
Subject: [avr-gcc-list] About loop (mis-)optimizations
Date: Sun, 29 Apr 2001 13:42:31 +0200

Hello world\n

since Denis has repeatedly claimed that the misoptimization of dead
loops were a feature of the recent gcc, i finally took the time to
test it.  Given the simple C program:

int main(void)
{
        unsigned i;

        for (i = 50000; i; i--) ;

        return 0;
}

...i compiled it as well for an i386 as an avr target.  Compiler
sources are from the same snapshot:

% ggcc -v
Reading specs from /tmp/pkg/lib/gcc-lib/i386-portbld-freebsd5.0/3.0/specs
Configured with: ./../gcc-20010320/configure --disable-nls --with-gnu-as 
--with-gnu-ld 
--with-gxx-include-dir=/tmp/pkg/lib/gcc-lib/i386-portbld-freebsd5.0/3.0/include/g++
 --disable-shared --prefix=/tmp/pkg i386-portbld-freebsd5.0
gcc version 3.0 20010320 (prerelease)

% avr-gcc -v
Reading specs from /usr/local/lib/gcc-lib/avr/3.0/specs
Configured with: ./configure --target=avr --prefix=/usr/local i386--freebsd5.0
gcc version 3.0 20010320 (prerelease)

The resulting .s file for -O2 optimization is (irrelevant parts
stripped for previty):

i386:

main:
        movl    $50000, %eax
        pushl   %ebp
        testl   %eax, %eax
        movl    %esp, %ebp
        je      .L8
        .p2align 2
.L5:
        decl    %eax
        jne     .L5
.L8:

Looks OK.  The loop counter is initialized with 50000, and decremented
(by one) for each iteration.

avr:

/* prologue end (size=4) */
        ldi r24,lo8(50000)
        ldi r25,hi8(50000)
.L5:
        subi r24,lo8(-(-625))
        sbci r25,hi8(-(-625))
        brne .L5
/* epilogue: frame size=0 */

The loop counter is also initialized with 50000, but then decremented
by 625 per iteration.  This looks broken to me, really.

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]