[Bug c++/18612] New: Loop optimiser generates incorrect code.

2004-11-22 Thread gccbug at sarek dot cc
When the code below is compiled with -O3, func2() is called on each iteration.
The .s shows that the the comparison to Array has been moved outside of the loop
which is incorrect. If Array is not constant working code is produced, working
code is also produced if I use -fold-unroll-loops. If I don't call a function
say simply increment j, then correct code is produced too.

The other options used are:
-O3 -m68000 -msoft-float -fno-exceptions

--
const unsigned char Array[6] = { 10, 10, 10, 0, 0 ,0 };
void func2(void);

int j=0;

void func(void)
{
unsigned char i;

for(i=0; i<6; i++)
{
if(Array[i] > 0)
{
func2();
}
}
}

void func2(void)
{
j++;
}
--

-- 
   Summary: Loop optimiser generates incorrect code.
   Product: gcc
   Version: 3.4.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gccbug at sarek dot cc
CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: cygwin
  GCC host triplet: cygwin
GCC target triplet: m68k-elf


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


[Bug rtl-optimization/18612] Loop optimiser generates incorrect code.

2004-12-13 Thread gccbug at sarek dot cc

--- Additional Comments From gccbug at sarek dot cc  2004-12-13 18:29 
---
I'm sorry I forget to include "-fno-inline" as a compiler option I'm using. When
I compile without "-fno-inline" I do get the same code as you posted here. 

This is the code produced using this option:

link.w %a6,#0
move.l %d2,-(%sp)
clr.b %d2
lea Array,%a0
tst.b (%a0)
jbne .L18
.align  2
.L7:
addq.b #1,%d2
cmp.b #5,%d2
jbls .L7
jbra .L16
.align  2
.L18:
jbsr _Z5func2v
addq.b #1,%d2
cmp.b #5,%d2
jbhi .L16
jbsr _Z5func2v
addq.b #1,%d2
cmp.b #5,%d2
jbls .L18
.L16:
move.l -4(%a6),%d2
unlk %a6
rts



John.

-- 


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