This is the mail archive of the 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] Don't push stack pointer. (revised)


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

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

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 *);
bug1 (void)
  void *p = __builtin_alloca (0x100);
  func (1, 2, 3, p);


Kazu Hirata

2001-07-23  Kazu Hirata  <>

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

RCS file: /cvs/gcc/gcc/gcc/config/h8300/,v
retrieving revision
diff -u -r1.23.4.5
---	2001/06/13 17:39:34
+++	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]