public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18612] New: Loop optimiser generates incorrect code.
@ 2004-11-22 19:12 gccbug at sarek dot cc
2004-11-22 19:16 ` [Bug rtl-optimization/18612] " pinskia at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: gccbug at sarek dot cc @ 2004-11-22 19:12 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug rtl-optimization/18612] Loop optimiser generates incorrect code.
2004-11-22 19:12 [Bug c++/18612] New: Loop optimiser generates incorrect code gccbug at sarek dot cc
@ 2004-11-22 19:16 ` pinskia at gcc dot gnu dot org
2004-12-13 8:53 ` bernie at develer dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-22 19:16 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |rtl-optimization
Keywords| |wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18612
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug rtl-optimization/18612] Loop optimiser generates incorrect code.
2004-11-22 19:12 [Bug c++/18612] New: Loop optimiser generates incorrect code gccbug at sarek dot cc
2004-11-22 19:16 ` [Bug rtl-optimization/18612] " pinskia at gcc dot gnu dot org
@ 2004-12-13 8:53 ` bernie at develer dot com
2004-12-13 18:29 ` gccbug at sarek dot cc
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: bernie at develer dot com @ 2004-12-13 8:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bernie at develer dot com 2004-12-13 08:53 -------
What happens here is that func2() is inlined
inside func(), and j loaded into %a0 before
entering the loop, for improved speed.
The test for Array[i] > 0 is correctly
performed *inside* the loop.
This PR appears to be invalid to me, but I'll
wait for a clarification before closing it.
func:
link.w %a6,#0
clr.b %d0
lea Array,%a1
moveq #0,%d1
move.l j,%a0
.align 2
.L8:
move.b %d0,%d1
tst.b (%a1,%d1.l)
jbeq .L5
addq.l #1,%a0
.L5:
addq.b #1,%d0
cmp.b #5,%d0
jbls .L8
move.l %a0,j
unlk %a6
rts
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18612
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug rtl-optimization/18612] Loop optimiser generates incorrect code.
2004-11-22 19:12 [Bug c++/18612] New: Loop optimiser generates incorrect code gccbug at sarek dot cc
2004-11-22 19:16 ` [Bug rtl-optimization/18612] " pinskia at gcc dot gnu dot org
2004-12-13 8:53 ` bernie at develer dot com
@ 2004-12-13 18:29 ` gccbug at sarek dot cc
2005-06-10 15:58 ` tom at hukatronic dot cz
2005-06-15 3:24 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: gccbug at sarek dot cc @ 2004-12-13 18:29 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug rtl-optimization/18612] Loop optimiser generates incorrect code.
2004-11-22 19:12 [Bug c++/18612] New: Loop optimiser generates incorrect code gccbug at sarek dot cc
` (2 preceding siblings ...)
2004-12-13 18:29 ` gccbug at sarek dot cc
@ 2005-06-10 15:58 ` tom at hukatronic dot cz
2005-06-15 3:24 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: tom at hukatronic dot cz @ 2005-06-10 15:58 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From tom at hukatronic dot cz 2005-06-10 15:58 -------
This seems to be fixed in GCC 4.0.0. This is the code produced by GCC 4.0.0 with following command
line:
~/Projects/gcc_m68k/bin/m68k-bsd-elf-gcc -S -O3 -m68000 -msoft-float -fno-exceptions -fno-
inline test.c
func:
link.w %fp,#0
move.l %a2,-(%sp)
lea Array,%a2
tst.b (%a2)
jbeq .L5
jbra .L13
.L12:
tst.b (%a2)
jbeq .L5
.L13:
jbsr func2
.L5:
addq.l #1,%a2
cmp.l #Array+6,%a2
jbne .L12
move.l -4(%fp),%a2
unlk %fp
rts
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18612
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug rtl-optimization/18612] Loop optimiser generates incorrect code.
2004-11-22 19:12 [Bug c++/18612] New: Loop optimiser generates incorrect code gccbug at sarek dot cc
` (3 preceding siblings ...)
2005-06-10 15:58 ` tom at hukatronic dot cz
@ 2005-06-15 3:24 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-15 3:24 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-06-15 03:24 -------
Closing as fixed then.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.0.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18612
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-06-15 3:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-22 19:12 [Bug c++/18612] New: Loop optimiser generates incorrect code gccbug at sarek dot cc
2004-11-22 19:16 ` [Bug rtl-optimization/18612] " pinskia at gcc dot gnu dot org
2004-12-13 8:53 ` bernie at develer dot com
2004-12-13 18:29 ` gccbug at sarek dot cc
2005-06-10 15:58 ` tom at hukatronic dot cz
2005-06-15 3:24 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).