This is the mail archive of the gcc-bugs@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]

[Bug target/16562] [ H8300 Target] Wrong code with -O2, -O3 optimizations


------- 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


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