This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/6080: incorrect loop optimizations



>Number:         6080
>Category:       optimization
>Synopsis:       incorrect loop optimizations
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 28 02:56:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Anders Blomdell <anders.blomdell@control.lth.se>
>Release:        3.0.4
>Organization:
>Environment:
System: Linux aljazari 2.4.13-KURT #2 Thu Nov 8 10:49:33 CET 2001 i686 unknown
Architecture: i686

        <machine, os, target, libraries (multiple lines)>
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: m68k-unknown-elf
configured with: ../../../gcc-3.0.4/configure --prefix=/usr/local/packages/cross
/m68k-elf --target=m68k-elf --with-newlib : (reconfigured) ../../../gcc-3.0.4/co
nfigure --prefix=/usr/local/packages/cross/m68k-elf --target=m68k-elf --with-new
lib : (reconfigured) ../../../gcc-3.0.4/configure --with-gcc-version-trigger=/wo
rk/aljazari2/andersb/gnu/gcc-3.0.4/gcc/version.c --host=i686-pc-linux-gnu --pref
ix=/usr/local/packages/cross/m68k-elf --target=m68k-elf --with-newlib --enable-c
hecking=misc,tree,rtl,gc,gcac
>Description:
gcc -O5 makes incorrect loop optimizations on the following code:

// case A: h get called infinite times
static void ug0(unsigned int count)
{
  while (count > 0) { ug0(0); h(); count--; }
}
void uf0() { ug0(1000); }

// case B: h gets called only once
static void sg0(int count)
{
  while (count > 0) { sg0(0); h(); count--; }
}

void sf0() { sg0(1000); }

This is the m68k code that gets produced (ppc code exhibits same problem...)

80000128 <uf0>:
80000128:       4e56 0000       linkw %fp,#0
8000012c:       42a7            clrl %sp@-
8000012e:       6120            bsrs 80000150 <ug0>
80000130:       61ff ffff ffda  bsrl 8000010c <h>
80000136:       588f            addql #4,%sp
80000138:       60f2            bras 8000012c <uf0+0x4>
8000013a:       4e71            nop

8000013c <sf0>:
8000013c:       4e56 0000       linkw %fp,#0
80000140:       42a7            clrl %sp@-
80000142:       6130            bsrs 80000174 <sg0>
80000144:       61ff ffff ffc6  bsrl 8000010c <h>
8000014a:       588f            addql #4,%sp
8000014c:       4e5e            unlk %fp
8000014e:       4e75            rts


>How-To-Repeat:
Compile the testprogram with -O5
>Fix:
Turn off optimization
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]