public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16562] New: [ H8300 Target] Wrong code with -O2, -O3 optimizations
@ 2004-07-15 9:46 asgarij at kpitcummins dot com
2004-07-15 14:19 ` [Bug target/16562] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: asgarij at kpitcummins dot com @ 2004-07-15 9:46 UTC (permalink / raw)
To: gcc-bugs
Following test case generates wrong code with optimization option -O2 or O3.
Details are as under.
h8300-elf-gcc -v
----------------
Configured with: /home/kpit/fsfsrc/downloads/gcc-3.5-20040711/configure --
enable-languages=c,c++ --target=h8300-elf --with-newlib --
prefix=/home/nitins2/intmdt_share/gnuh8300_v0403_elf-1
Thread model: single
gcc version 3.5-GNUH8_v0403
----------------------------------------------
Commandline: h8300-elf-gcc test.c -ms -m2600s -S -O2
//test.c
void theLoop( void )
{
unsigned long int cnt;
cnt = 0L;
do
cnt++;
while (cnt < 1000000L);
}
//test.c
//test.s
.file "test.c"
.h8300s
.section .text
.align 2
.align 1
.global _theLoop
_theLoop:
mov.l er6,@-er7
mov.l er7,er6
mov.l #999999,er2
.L2:
sub.l #50,er2 !This should be 1
mov.l er2,er2
bge .L2
mov.l @er7+,er6
rts
.size _theLoop, .-_theLoop
.end
//test.s
Additional Info: This bug comes with target options -mh,-ms and -ms2600 only.
--
Summary: [ H8300 Target] Wrong code with -O2, -O3 optimizations
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: asgarij at kpitcummins dot com
CC: asgarij at kpitcummins dot com,gcc-bugs at gcc dot gnu
dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: h8300-unknown-elf
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16562
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/16562] [ H8300 Target] Wrong code with -O2, -O3 optimizations
2004-07-15 9:46 [Bug c/16562] New: [ H8300 Target] Wrong code with -O2, -O3 optimizations asgarij at kpitcummins dot com
@ 2004-07-15 14:19 ` pinskia at gcc dot gnu dot org
2004-08-03 5:24 ` anilp1 at kpitcummins dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-15 14:19 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|critical |normal
Component|c |target
Keywords| |wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16562
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/16562] [ H8300 Target] Wrong code with -O2, -O3 optimizations
2004-07-15 9:46 [Bug c/16562] New: [ H8300 Target] Wrong code with -O2, -O3 optimizations asgarij at kpitcummins dot com
2004-07-15 14:19 ` [Bug target/16562] " pinskia at gcc dot gnu dot org
@ 2004-08-03 5:24 ` anilp1 at kpitcummins dot com
2004-08-04 5:20 ` anilp1 at kpitcummins dot com
2004-08-16 7:08 ` kazu at cs dot umass dot edu
3 siblings, 0 replies; 5+ messages in thread
From: anilp1 at kpitcummins dot com @ 2004-08-03 5:24 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |anilp1 at kpitcummins dot
| |com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16562
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/16562] [ H8300 Target] Wrong code with -O2, -O3 optimizations
2004-07-15 9:46 [Bug c/16562] New: [ H8300 Target] Wrong code with -O2, -O3 optimizations asgarij at kpitcummins dot com
2004-07-15 14:19 ` [Bug target/16562] " pinskia at gcc dot gnu dot org
2004-08-03 5:24 ` anilp1 at kpitcummins dot com
@ 2004-08-04 5:20 ` anilp1 at kpitcummins dot com
2004-08-16 7:08 ` kazu at cs dot umass dot edu
3 siblings, 0 replies; 5+ messages in thread
From: anilp1 at kpitcummins dot com @ 2004-08-04 5:20 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From anilp1 at kpitcummins dot com 2004-08-04 05:20 -------
Hi,
The workaround to avoid bug is to pass either of following option along
with -O2 ,
-fno-loop-optimize
-fno-strength-reduce
This bug is not target dependent as was first impression.
Since counting variable is of type unsigned long, the number of instructions
in loop for plain H8/300 are 7. So problem doesn't crop up for plain H8/300.
If we change data type of counting variable to unsigned int (16 bits) and
value also within range of 16 bits ( less than 65535) then bug can be seen in
case of plain H8/300.
Bug is not observed in following program code,
//test.c
void theLoop( void )
{
unsigned long int cnt;
cnt = 0L;
do{
cnt++;
asm("nop");
} while (cnt < 1000000L);
}
//test.c
Compiled with -S -O2 -ms options.
The number of instructions in loop becomes 4 in above case. Hence bug is not
observed.
I tracked the problem to loop.c, line no. 5358 (gcc 3.5 snapshot dated 25 July
2004).
Following call doesn't take place for insn_count more than 4
since "unrolled_insn_copies <= insn_count" this condition is dissatisfied.
unroll_loop (loop, insn_count, 1);
In case of H8S target and insn_count 3, call takes place and the magic number
50 appears instead of 1.
This magic number is also dependent on number of iterations of loop.
Will it be ok to add additional condition as insn_count > 4 while calling
unroll_loop at line 5358 ?
Please comment.
Regards,
Anil Paranjpe
KPIT Cummins InfoSystems Ltd.
Pune, India
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH and H8 Series.
The following site also offers free technical support to its users.
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU tools were released on June 1, 2004.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16562
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/16562] [ H8300 Target] Wrong code with -O2, -O3 optimizations
2004-07-15 9:46 [Bug c/16562] New: [ H8300 Target] Wrong code with -O2, -O3 optimizations asgarij at kpitcummins dot com
` (2 preceding siblings ...)
2004-08-04 5:20 ` anilp1 at kpitcummins dot com
@ 2004-08-16 7:08 ` kazu at cs dot umass dot edu
3 siblings, 0 replies; 5+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-08-16 7:08 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From kazu at cs dot umass dot edu 2004-08-16 07:07 -------
I doubt there is anything in the C language specification that
prohibits the compiler from removing or shortening these empty loops.
To guarantee the presevation of the loop iterations, you need to use
asm ("nop") as you have demonstrated already.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16562
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-08-16 7:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-15 9:46 [Bug c/16562] New: [ H8300 Target] Wrong code with -O2, -O3 optimizations asgarij at kpitcummins dot com
2004-07-15 14:19 ` [Bug target/16562] " pinskia at gcc dot gnu dot org
2004-08-03 5:24 ` anilp1 at kpitcummins dot com
2004-08-04 5:20 ` anilp1 at kpitcummins dot com
2004-08-16 7:08 ` kazu at cs dot umass dot edu
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).