Bug using -O2 with cross compiler
Ed Hepler
hepler@vlsi-concepts.com
Sat Nov 20 23:20:00 GMT 1999
I wrote:
> I believe that I have found a bug when using GCC as a cross compiler
> to target the MC68000 from a Linux platform.
>
> I am using gcc-2.95.2
>
> The gcc command is:
>
> m68k-coff-gcc -m68000 -g -ggdb -O2 -c blink_led.c
>
> The code fragment being compiled is:
>
> #define DELAY 5000000
>
> void
> delay() {
> int i;
>
> for(i= 0; i < DELAY; i++);
> }
>
>
> The produced code looks like:
>
> 00000408 <delay>:
> 408: 4e56 0000 linkw %fp,#0
> 40c: 203c 004c 4b3f movel #4999999,%d0
> 412: 51c8 fffe dbf %d0,412 <delay+0xa>
> 416: 4240 clrw %d0
> 418: 5380 subql #1,%d0
> 41a: 64f6 bccs 412 <delay+0xa>
> 41c: 4e5e unlk %fp
> 41e: 4e75 rts
>
>
> The problem(s):
>
> 1. The dbcc instruction only acts upon the low order 16 bits of the
> specified register. So, loading an initial value into D0 which
> extends into the upper half of the register is a problem...
>
> 2. I'm not quite sure why the compiler generates the instructions at
> locations 416, 418, and 41a... In fact, don't these instructions
> put this into an infinite loop?
>
> 416: clears D0
> 418: subtracts 1 from D0 (leaving 0xffffffff in D0, no carry out)
> 41a: branches on carry clear (always) back to the beginning of the
> original loop...
Whoops... There is no carry, but a borrow, so this doesn't result in
an infinite loop...
> I suspect that these extra instructions were supposed to handle the
> upper 16 bits of the register??? but are maybe somehow misguided???
But I still don't understand why the code was emitted...
> The code produced with -O or -O1 seems to be OK...
Problem 1 remains...
Thanks,
Ed Hepler
Dr. Edward L. Hepler
President, Adjunct Professor,
VLSI Concepts, Inc. Villanova University Graduate Courses:
VLSI and System ECE-8440 System Design and Modeling
Architecture, Design, ECE-8445 Advanced Computer Architecture
and CAD ECE-8460 VLSI Design
email: hepler@vlsi-concepts.com or elh@ece.vill.edu
voice: (610) 408-9121
fax: (610) 408-9121
www: http://www.vlsi-concepts.com Read: I Cor 8:6
More information about the Gcc-bugs
mailing list