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]

Re: PING: PATCH: PR middle-end/37843:[4.4 Regression] unaligned stack in main due to tail call optimizatiP


On Mon, Nov 24, 2008 at 04:43:42PM -0800, H.J. Lu wrote:
> On Wed, Nov 19, 2008 at 10:12 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> > On Mon, Nov 10, 2008 at 10:50 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> >> On Wed, Nov 5, 2008 at 10:06 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> >>> On Wed, Nov 5, 2008 at 8:49 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> >>>> Hello!
> >>>>
> >>>>> Here is the updated version. When we update stack boundary before
> >>>>> expanding a function, we don't need to check parm_stack_boundary
> >>>>> in expand_stack_alignment.  Tested on Linux/ia32, Linux/Intel64 and
> >>>>> Linux/ia64.  OK for trunk?
> >>>>>
> >>>>> Thanks.
> >>>>>
> >>>>>
> >>>>> --
> >>>>> H.J.
> >>>>> ----
> >>>>> gcc/
> >>>>>
> >>>>> 2008-11-04  H.J. Lu  <hongjiu.lu@intel.com>
> >>>>>            Joey Ye  <joey.ye@intel.com>
> >>>>>
> >>>>>        PR middle-end/37843
> >>>>>        * cfgexpand.c (expand_stack_alignment): Don't update stack
> >>>>>        boundary nor check incoming stack boundary here.
> >>>>>        (gimple_expand_cfg): Update stack boundary and check incoming
> >>>>>        stack boundary here.
> >>>>>
> >>>>>        * config/i386/i386.c (ix86_function_ok_for_sibcall): Return
> >>>>>        false if we need to align the outgoing stack.
> >>>>>        (ix86_update_stack_boundary): Check parm_stack_boundary.
> >>>>>
> >>>>> gcc/testsuite/
> >>>>>
> >>>>> 2008-11-04  H.J. Lu  <hongjiu.lu@intel.com>
> >>>>>
> >>>>>        PR middle-end/37843
> >>>>>        * gcc.target/i386/align-main-3.c: New.
> >>>>>        * gcc.target/i386/pr37843-1.c: Likewise.
> >>>>>        * gcc.target/i386/pr37843-2.c: Likewise.
> >>>>>        * gcc.target/i386/pr37843-3.c: Likewise.
> >>>>>
> >>>>
> >>>>> --- gcc/testsuite/gcc.target/i386/align-main-3.c.sibcall        2008-11-04
> >>>>> 08:33:41.000000000 -0800
> >>>>> +++ gcc/testsuite/gcc.target/i386/align-main-3.c        2008-11-04
> >>>>> 08:33:41.000000000 -0800
> >>>>> @@ -0,0 +1,14 @@
> >>>>> +/* Test for stack alignment with sibcall optimization.  */
> >>>>> +/* { dg-do compile { target { { i?86-*-linux* x86_64-*-linux* } && ilp32
> >>>>> } } } */
> >>>>>
> >>>>
> >>>>
> >>>> It is enough to check for "target { *-*-linux*  && ilp32 }", since we
> >>>> execute gcc.target/i386 for i?86 and x86_64 targets only.
> >>>>
> >>>>> --- gcc/testsuite/gcc.target/i386/pr37843-3.c.sibcall   2008-11-04
> >>>>> 08:33:41.000000000 -0800
> >>>>> +++ gcc/testsuite/gcc.target/i386/pr37843-3.c   2008-11-04
> >>>>> 08:33:41.000000000 -0800
> >>>>> @@ -0,0 +1,13 @@
> >>>>> +/* Test for stack alignment with sibcall optimization.  */
> >>>>> +/* { dg-do compile { target { { i?86-*-linux* x86_64-*-linux* } && ilp32
> >>>>> } } } */
> >>>>>
> >>>>
> >>>> Same here.
> >>>>
> >>>
> >>> Here is the updated patch. Tested on Linux/ia32, Linux/Intel64 and
> >>> Linux/ia64.  OK for trunk?
> >>>
> >>> Thanks.
> >>>
> >>
> >> Ping.
> >>
> >
> > PING.
> >
> 
> PING.
> 
> 

I checked in the x86 backend change as well as testcases, which will
fail without the middle-end change.

Here is the middle-end change.  Jeff, Ian, Richard, Diego, could you
take a look at it?

Thanks.


H.J.
----
2008-11-25  H.J. Lu  <hongjiu.lu@intel.com>
	    Joey Ye  <joey.ye@intel.com>

	PR middle-end/37843
	* cfgexpand.c (expand_stack_alignment): Don't update stack
	boundary nor check incoming stack boundary here.
	(gimple_expand_cfg): Update stack boundary and check incoming
	stack boundary here.

--- gcc/cfgexpand.c.sibcall	2008-10-09 07:05:53.000000000 -0700
+++ gcc/cfgexpand.c	2008-11-04 21:44:12.000000000 -0800
@@ -2218,7 +2218,7 @@ static void
 expand_stack_alignment (void)
 {
   rtx drap_rtx;
-  unsigned int preferred_stack_boundary, incoming_stack_boundary;
+  unsigned int preferred_stack_boundary;
 
   if (! SUPPORTS_STACK_ALIGNMENT)
     return;
@@ -2231,10 +2231,6 @@ expand_stack_alignment (void)
   gcc_assert (crtl->stack_alignment_needed
 	      <= crtl->stack_alignment_estimated);
 
-  /* Update stack boundary if needed.  */
-  if (targetm.calls.update_stack_boundary)
-    targetm.calls.update_stack_boundary (); 
-
   /* Update crtl->stack_alignment_estimated and use it later to align
      stack.  We check PREFERRED_STACK_BOUNDARY if there may be non-call
      exceptions since callgraph doesn't collect incoming stack alignment
@@ -2249,15 +2245,8 @@ expand_stack_alignment (void)
   if (preferred_stack_boundary > crtl->stack_alignment_needed)
     crtl->stack_alignment_needed = preferred_stack_boundary;
 
-  /* The incoming stack frame has to be aligned at least at
-     parm_stack_boundary.  */
-  if (crtl->parm_stack_boundary > INCOMING_STACK_BOUNDARY)
-    incoming_stack_boundary = crtl->parm_stack_boundary;
-  else
-    incoming_stack_boundary = INCOMING_STACK_BOUNDARY;
-
   crtl->stack_realign_needed
-    = incoming_stack_boundary < crtl->stack_alignment_estimated;
+    = INCOMING_STACK_BOUNDARY < crtl->stack_alignment_estimated;
   crtl->stack_realign_tried = crtl->stack_realign_needed;
 
   crtl->stack_realign_processed = true;
@@ -2362,6 +2351,17 @@ gimple_expand_cfg (void)
   if (crtl->stack_protect_guard)
     stack_protect_prologue ();
 
+  /* Update stack boundary if needed.  */
+  if (SUPPORTS_STACK_ALIGNMENT)
+    {
+      if (targetm.calls.update_stack_boundary)
+	targetm.calls.update_stack_boundary ();
+      
+      /* The incoming stack frame has to be aligned at least at
+	 parm_stack_boundary.  */
+      gcc_assert (crtl->parm_stack_boundary <= INCOMING_STACK_BOUNDARY);
+    }
+
   /* Register rtl specific functions for cfg.  */
   rtl_register_cfg_hooks ();
 


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