i386: Update preferred stack boundary for leaf functions

preferred_stack_boundary may not be the minimum stack alignment.  For
leaf functions without TLS access, max_used_stack_slot_alignment may be
smaller.  We should update preferred_stack_boundary for leaf functions.

gcc/

	PR target/82166
	* config/i386/i386.c (ix86_finalize_stack_frame_flags): Properly
	compute the minimum stack alignment.  Also update preferred stack
	boundary for leaf functions.

gcc/testsuite/

	PR target/82166
	* gcc.target/i386/pr82166.c: New test.

From-SVN: r252895
This commit is contained in:
H.J. Lu 2017-09-17 21:11:04 +00:00 committed by H.J. Lu
parent 62d3c075d5
commit 01f44e44fa
4 changed files with 38 additions and 5 deletions

View File

@ -1,3 +1,10 @@
2017-09-17 H.J. Lu <hongjiu.lu@intel.com>
PR target/82166
* config/i386/i386.c (ix86_finalize_stack_frame_flags): Properly
compute the minimum stack alignment. Also update preferred stack
boundary for leaf functions.
2017-09-16 Richard Sandiford <richard.sandiford@linaro.org>
PR tree-optimization/82228

View File

@ -14257,11 +14257,12 @@ ix86_finalize_stack_frame_flags (void)
unsigned int incoming_stack_boundary
= (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
unsigned int stack_alignment
= (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor
? crtl->max_used_stack_slot_alignment
: crtl->stack_alignment_needed);
unsigned int stack_realign
= (incoming_stack_boundary
< (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor
? crtl->max_used_stack_slot_alignment
: crtl->stack_alignment_needed));
= (incoming_stack_boundary < stack_alignment);
bool recompute_frame_layout_p = false;
if (crtl->stack_realign_finalized)
@ -14306,7 +14307,9 @@ ix86_finalize_stack_frame_flags (void)
HARD_FRAME_POINTER_REGNUM);
/* The preferred stack alignment is the minimum stack alignment. */
unsigned int stack_alignment = crtl->preferred_stack_boundary;
if (stack_alignment > crtl->preferred_stack_boundary)
stack_alignment = crtl->preferred_stack_boundary;
bool require_stack_frame = false;
FOR_EACH_BB_FN (bb, cfun)
@ -14349,6 +14352,10 @@ ix86_finalize_stack_frame_flags (void)
= incoming_stack_boundary;
crtl->stack_alignment_needed
= incoming_stack_boundary;
/* Also update preferred_stack_boundary for leaf
functions. */
crtl->preferred_stack_boundary
= incoming_stack_boundary;
}
}
else

View File

@ -1,3 +1,8 @@
2017-09-17 H.J. Lu <hongjiu.lu@intel.com>
PR target/82166
* gcc.target/i386/pr82166.c: New test.
2017-09-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/82173

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-Os" } */
void foo (void);
int a, b, c;
int
main (void)
{
int j;
for (; c;)
a = b;
for (; j;)
foo ();
}