Hi,

When I compile this C code:

#include <stdint.h>

inline int mid_pred(int a, int b, int c)
{
    int t= (a-b)&((a-b)>>31);
    a-=t;
    b+=t;
    b-= (b-c)&((b-c)>>31);
    b+= (a-b)&((a-b)>>31);

    return b;
}

I get this asm output from GCC 4.3.2 (-m68060 -fomit-frame-pointer -O[2/3]):

#NO_APP
        .text
        .even
        .globl  _mid_pred
_mid_pred:
        movem.l #14336,-(sp)
        move.l 16(sp),d2
        move.l 20(sp),d1
        move.l d2,d0
        sub.l d1,d0
        move.l d0,d4
        add.l d4,d4
        subx.l d4,d4
        and.l d0,d4
        add.l d4,d1
        move.l d1,d3
        sub.l 24(sp),d3
        move.l d3,d0
        add.l d0,d0
        subx.l d0,d0
        and.l d3,d0
        sub.l d0,d1
        sub.l d4,d2
        sub.l d1,d2
        move.l d2,d0
        add.l d0,d0
        subx.l d0,d0
        and.l d2,d0
        add.l d1,d0
        movem.l (sp)+,#28
        rts


When I use GCC 4.4.[0/1/2] with -O2/-O3 option I get worse asm output (2
additional move.ls):

#NO_APP
        .text
        .even
        .globl  _mid_pred
_mid_pred:
        movem.l #14336,-(sp)
        move.l 16(sp),d1
        move.l 20(sp),d0
        move.l d1,d3
        sub.l d0,d3
        move.l d3,d2
        add.l d2,d2
        subx.l d2,d2
        and.l d3,d2
        add.l d2,d0
        move.l d0,d4
        sub.l 24(sp),d4
        move.l d4,d3
        add.l d3,d3
        subx.l d3,d3
        and.l d4,d3
        sub.l d3,d0
        move.l d0,d3
        sub.l d2,d1
        sub.l d0,d1
        move.l d1,d2
        add.l d2,d2
        subx.l d2,d2
        and.l d1,d2
        move.l d2,d0
        add.l d3,d0
        movem.l (sp)+,#28
        rts

The problematic optimization is -fregmove (-m68060 -fomit-frame-pointer -O[2/3]
-fno-regmove):

#NO_APP
        .text
        .even
        .globl  _mid_pred
_mid_pred:
        movem.l #14336,-(sp)
        move.l 16(sp),d0
        move.l 20(sp),d1
        move.l d0,d2
        sub.l d1,d2
        move.l d2,d3
        add.l d3,d3
        subx.l d3,d3
        and.l d3,d2
        add.l d2,d1
        move.l d1,d3
        sub.l 24(sp),d3
        move.l d3,d4
        add.l d4,d4
        subx.l d4,d4
        and.l d4,d3
        sub.l d3,d1
        sub.l d2,d0
        sub.l d1,d0
        move.l d0,d2
        add.l d2,d2
        subx.l d2,d2
        and.l d2,d0
        add.l d1,d0
        movem.l (sp)+,#28
        rts


-- 
           Summary: GCC 4.4.[0/1/2] generates worse code compared to GCC
                    4.3.2
           Product: gcc
           Version: 4.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ami_stuff at o2 dot pl
  GCC host triplet: i686-cygwin
GCC target triplet: m68k-amigaos


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41204

Reply via email to