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

[PATCH, H8/300]:Save SP in H8 tiny.


Hi,

H8 tiny i.e. H8300H NORMAL MODE doesn't save the stack pointer (SP)
during function calls. Hence wrong assembly code is generated when 
optimization option "-fomit-frame-pointer" is passed with any of the
optimization enabled.

Please find attached the patch that saves the SP during function
calls and hence generates correct assembly code.  

Below is a simple testcase that does not save the stack pointer during
the function call.
=====================================================================
unsigned int GetSth(unsigned char *ptrbaSrc,
                    unsigned int   wSize,
                    unsigned char  bMode,
                    unsigned char *ptrbaBuff)
{
  unsigned int wi;
  for(wi=0x0000; wi<wSize; wi++) ptrbaBuff[wi]=0x00;
  return 0;
}

int main(void)
{
  unsigned char baBuff[32];
  GetSth(0x00, 0x10, 0x00, baBuff);
  return(0);
}

COMMAND LINE :- h8300-elf-gcc -mh -mn -S -O2 -fomit-frame-pointer

BEFORE applying the patch 	mov.l	er7,@-er7

AFTER patch is applied        mov.w	r7,r6               
                              add.w	#-32,r7
The SP is saved during the function call.			  
=====================================================================

No new regressions found. Tested on GCC-4.2 snapshot.

=======================Start of Patch================================
ChangeLog
2006-05-23  Naveen.H.S <naveenh@kpitcummins.com>

           	* gcc/config/h8300/h8300.md: expand the peephole2 to
include 
            H8300 tiny target.

--- gcc/config/h8300/h8300.md.orig      2006-05-10 14:48:18.000000000
+0530
+++ gcc/config/h8300/h8300.md   2006-05-10 14:50:03.000000000 +0530
@@ -4595,7 +4595,7 @@
                    (plus:HI (reg:HI SP_REG) (const_int -4)))
               (set (mem:HI (plus:HI (reg:HI SP_REG) (const_int -2)))
                    (match_operand:HI 0 "register_operand" ""))])]
-  "TARGET_H8300S && TARGET_NORMAL_MODE && REGNO (operands[0]) !=
SP_REG"
+  "(TARGET_H8300S || TARGET_H8300H)&& TARGET_NORMAL_MODE && REGNO 
(operands[0]) != SP_REG"
   [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
        (match_dup 0))]
   "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")

=======================End Of Patch================================

Regards,

Naveen.H.S.
KPIT Cummins Infosystems Ltd,
Pune ( INDIA ) 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH, H8 and M16C
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 April 1, 2006.   


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