[Fwd: Re: problem with GCC 2.95.3 (m68k target)]

Joel Sherrill joel.sherrill at OARcorp.com
Wed Jan 30 12:56:40 UTC 2002



Stan has sent me some code fragments which show what he
things the problem is.  Perhaps someone else can see what
is happening and if there is a patch.

-------- Original Message --------
From: "Stan" <zylog at club-internet.fr>
Subject: Re: problem with GCC 2.95.3 (m68k target)
To: "Joel Sherrill" <joel.sherrill at OARcorp.com>


> 
> Stan wrote:
> > 
> > Hi,
> > 
> > I think that gcc 2.95.3 compile no properly.
> > How can I do ?

 I  to go too far  ? Perhaps...


> What do you mean?  I am sorry for not understanding.


A example :

/*  not called directly (callback function ) */
int foo(const struct termios *t)
{
int var2;
volatile unsigned char *var3=0;


    switch(cfgetospeed (t)){
        case 0: var3=1; break;
        case 1: var3=2; break;
        case 2: var3=3; break;
        case 3: var3=4; break;
        case 4: var3=5; break;
        default : var3=1;
    }

    switch(cfgetospeed (t)){
        case 0: var2+=1; break;
        case 1: var2+=2; break;
        case 2: var2+=1; break;
        case 3: var2+=2; break;
        case 4: var2+=1; break;
        default : var2=0;
    }


    *(var3+0) = 1;
    *(var3+1) = 2;
    *(var3+2) = 3;
    *(var3+3) = 4;

    return 0;
}


[CFLAG_OPTIMIZE_V with -O4 and -fomit-frame-pointer ]
test##foo#
0000055A 2F0A           move.l    A2,-(A7)
0000055C 2F02           move.l    D2,-(A7)
0000055E 242F000C       move.l    ($000C,A7),D2
00000562 2F02           move.l    D2,-(A7)
00000564 45F900000C04   lea       $00000C04,A2
0000056A 4E92           jsr       (A2)
0000056C 588F           addq.l    #4,A7
0000056E 204A           movea.l   A2,A0
00000570 7204           moveq     #4,D1
00000572 B280           cmp.l     D0,D1
00000574 652C           bcs.s     $000005A2
00000576 D080           add.l     D0,D0
00000578 303B0806       move.w    ($06,PC,D0.L*1),D0
0000057C 4EFB0002       jmp       ($02,PC,D0.W*1)
00000580 0022000A       ori.b     #$0A,-(A2)
00000584 00100016       ori.b     #$16,(A0)
00000588 001C347C       ori.b     #$7C,(A4)+
0000058C 00026016       ori.b     #$16,D2
00000590 347C0003       movea.w   #$0003,A2
00000594 6010           bra.s     $000005A6
00000596 347C0004       movea.w   #$0004,A2
0000059A 600A           bra.s     $000005A6
0000059C 347C0005       movea.w   #$0005,A2
000005A0 6004           bra.s     $000005A6
000005A2 347C0001       movea.w   #$0001,A2
000005A6 2F02           move.l    D2,-(A7)
000005A8 4E90           jsr       (A0)
000005AA 588F           addq.l    #4,A7
000005AC 4E71           nop

missing that :

    *(var3+0) = 1;
    *(var3+1) = 2;
    *(var3+2) = 3;
    *(var3+3) = 4;

and no return (RTS),  perhaps ggc believes that it is a inline function
?
But, why it cut few code ?


The same source with options below.

[ CFLAG_OPTIMIZE_V with -O0 and -fomit-frame-pointer ]

test##foo#
0000055C 4FEFFFF4       lea       ($FFF4,A7),A7
00000560 2F0E           move.l    A6,-(A7)
test##foo#{}
00000562 42AF0004       clr.l     ($0004,A7)
00000566 2F2F0014       move.l    ($0014,A7),-(A7)
0000056A 4EB900000CA8   jsr       $00000CA8   ;
cfgetospeed##cfgetospeed#
00000570 588F           addq.l    #4,A7
00000572 7204           moveq     #4,D1
00000574 B280           cmp.l     D0,D1
00000576 6544           bcs.s     $000005BC
00000578 2200           move.l    D0,D1
0000057A D081           add.l     D1,D0
0000057C 207C0000058A   movea.l   #$0000058A,A0
00000582 30300800       move.w    ($00,A0,D0.L*1),D0
00000586 4EFB0002       jmp       ($02,PC,D0.W*1)
0000058A 000A           ????
0000058C 0012001A       ori.b     #$1A,(A2)
00000590 0022002A       ori.b     #$2A,-(A2)
00000594 7001           moveq     #1,D0
00000596 2F400004       move.l    D0,($0004,A7)
0000059A 6026           bra.s     $000005C2
0000059C 7202           moveq     #2,D1
0000059E 2F410004       move.l    D1,($0004,A7)
000005A2 601E           bra.s     $000005C2
000005A4 7003           moveq     #3,D0
000005A6 2F400004       move.l    D0,($0004,A7)
000005AA 6016           bra.s     $000005C2
000005AC 7204           moveq     #4,D1
000005AE 2F410004       move.l    D1,($0004,A7)
000005B2 600E           bra.s     $000005C2
000005B4 7005           moveq     #5,D0
000005B6 2F400004       move.l    D0,($0004,A7)
000005BA 6006           bra.s     $000005C2
000005BC 7201           moveq     #1,D1
000005BE 2F410004       move.l    D1,($0004,A7)
000005C2 2F2F0014       move.l    ($0014,A7),-(A7)
000005C6 4EB900000CA8   jsr       $00000CA8   ;
cfgetospeed##cfgetospeed#
000005CC 588F           addq.l    #4,A7
000005CE 7204           moveq     #4,D1
000005D0 B280           cmp.l     D0,D1
000005D2 653A           bcs.s     $0000060E
000005D4 2200           move.l    D0,D1
000005D6 D081           add.l     D1,D0
000005D8 207C000005E6   movea.l   #$000005E6,A0
000005DE 30300800       move.w    ($00,A0,D0.L*1),D0
000005E2 4EFB0002       jmp       ($02,PC,D0.W*1)
000005E6 000A           ????
000005E8 00100016       ori.b     #$16,(A0)
000005EC 001C0022       ori.b     #$22,(A4)+
000005F0 52AF0008       addq.l    #1,($0008,A7)
000005F4 601C           bra.s     $00000612
000005F6 54AF0008       addq.l    #2,($0008,A7)
000005FA 6016           bra.s     $00000612
000005FC 52AF0008       addq.l    #1,($0008,A7)
00000600 6010           bra.s     $00000612
00000602 54AF0008       addq.l    #2,($0008,A7)
00000606 600A           bra.s     $00000612
00000608 52AF0008       addq.l    #1,($0008,A7)
0000060C 6004           bra.s     $00000612
0000060E 42AF0008       clr.l     ($0008,A7)
00000612 206F0004       movea.l   ($0004,A7),A0
00000616 10BC0001       move.b    #$01,(A0)
0000061A 206F0004       movea.l   ($0004,A7),A0
0000061E 5288           addq.l    #1,A0
00000620 10BC0002       move.b    #$02,(A0)
00000624 206F0004       movea.l   ($0004,A7),A0
00000628 5488           addq.l    #2,A0
0000062A 10BC0003       move.b    #$03,(A0)
0000062E 206F0004       movea.l   ($0004,A7),A0
00000632 5688           addq.l    #3,A0
00000634 10BC0004       move.b    #$04,(A0)
00000638 7000           moveq     #0,D0
0000063A 60000002       bra.w     $0000063E
0000063E 2C5F           movea.l   (A7)+,A6
00000640 4FEF000C       lea       ($000C,A7),A7
00000644 4E75           rts
 
It's right

> I think gcc generated correct code in your situation
> and you just did not recognize it.  

I don't think ;)

> No problem since
> we all learn from each other. if oyu don't ask
> questions, then you can't learn. :)

My question:

why gcc cut a few code ?
How to avoid a trap due to optimize ?


 Stan.



More information about the users mailing list