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]

[patch 3.0.1] h8300.md: Don't push stack pointer. (revised)


Hi,

Attached is a patch to prevent the stack pointer from being pushed.

If you use __builtin_alloca, the resulting assembly code includes a
push of the stack pointer.  If you push the stack pointer on H8, then
things happen in the following order:

1. the stack pointer is decremented
2. the contents of the stack pointer is transfered to stack

Thus the value on the stack is _not_ what you would expect.

The 1st hunk of the patch restricts movhi_push pattern to the 32-bit
machines (TARGET_H8300H and TARGET_H8300S) becasue the regular movhi
pattern includes a push insn for H8/300.

The 2nd part of the 1st hunk changes the condition used in the
anonymous movhi pattern to prevent the stack pointer from being
pushed.

The last hunk adds basically the same condition to the anonymous movsi
pattern to do the same thing as in the anonymous movhi pattern.

OK to apply to the branchif testing goes well?  I'll post a similar
patch for the mainline.

This patch obsoletes

http://gcc.gnu.org/ml/gcc-patches/2001-07/msg01629.html

as the old one had a typo.

By the way, here is a test case due to Peter Horton.  (I have no idea
on how to turn this into a test case for the testsuite.)

void func (int, int, int, void *);
 
void
bug1 (void)
{
  void *p = __builtin_alloca (0x100);
  func (1, 2, 3, p);
}

Thanks,

Kazu Hirata

2001-07-23  Kazu Hirata  <kazu@hxi.com>

	* h8300.md (movhi_push): Restrict to TARGET_H8300H and
	TARGET_H8300S.
	(anonymous movhi pattern): Prevent the stack pointer from
	being pushed.
	(anonymous movsi pattern): Likewise.

Index: h8300.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.md,v
retrieving revision 1.23.4.5
diff -u -r1.23.4.5 h8300.md
--- h8300.md	2001/06/13 17:39:34	1.23.4.5
+++ h8300.md	2001/07/23 21:56:29
@@ -173,22 +173,18 @@
 (define_insn "movhi_push"
   [(set (match_operand:HI 0 "push_operand" "=<")
 	(match_operand:HI 1 "register_operand" "r"))]
-  ""
-  "*
-{
-  if (TARGET_H8300)
-    return \"push.w	%T1\";
-  else
-    return \"push.l	%S1\";
-}"
-  [(set (attr "length") (if_then_else (eq_attr "cpu" "h8300") (const_int 2) (const_int 4)))
+  "TARGET_H8300H || TARGET_H8300S"
+  "push.l	%S1"
+  [(set_attr "length" "4")
    (set_attr "cc" "set_znv")])
 
 (define_insn ""
   [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
 	(match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
-  "register_operand (operands[0],HImode)
-   || register_operand (operands[1], HImode)"
+  "(register_operand (operands[0],HImode)
+    || register_operand (operands[1], HImode))
+   && !(push_operand (operands[0], HImode)
+        && operands[1] == stack_pointer_rtx)"
   "@
    sub.w	%T0,%T0
    mov.w	%T1,%T0
@@ -403,7 +399,9 @@
 	(match_operand:SI 1 "general_operand_src" "I,r,i,m,r,r,>,I,r,*a"))]
   "(TARGET_H8300S || TARGET_H8300H)
    && (register_operand (operands[0], SImode)
-       || register_operand (operands[1], SImode))"
+       || register_operand (operands[1], SImode))
+   && !(push_operand (operands[0], SImode)
+        && operands[1] == stack_pointer_rtx)"
   "*
 {
   switch (which_alternative)


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