From: H.J. Lu Date: Sun, 17 Sep 2017 21:11:04 +0000 (+0000) Subject: i386: Update preferred stack boundary for leaf functions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=01f44e44faf37fc34775b9e28e46d1c9243b247d;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e213db6e2a0..b09c7ce5812 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-09-17 H.J. Lu + + 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 PR tree-optimization/82228 diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index fa79762a922..4f0414ffa9d 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d40f08e13cf..47de348eb51 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-09-17 H.J. Lu + + PR target/82166 + * gcc.target/i386/pr82166.c: New test. + 2017-09-17 Paul Thomas PR fortran/82173 diff --git a/gcc/testsuite/gcc.target/i386/pr82166.c b/gcc/testsuite/gcc.target/i386/pr82166.c new file mode 100644 index 00000000000..8bc63e15231 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr82166.c @@ -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 (); +}