summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-07-06 08:58:46 -0700
committerH.J. Lu <hjl.tools@gmail.com>2018-01-11 13:10:33 -0800
commitfcf30d0b02c3b029e05d301a70116cc66249fa4f (patch)
tree419f1b8257da37fdff6122431d5e6442525e6d66
parentcc6420a8b984efa47496a8995d8b30945f58cb49 (diff)
downloadgcc-hjl/pr83330/gcc-7-branch.tar.gz
i386: Align stack frame if argument is passed on stackhjl/pr83330/gcc-7-branch
When a function call is removed, it may become a leaf function. But if argument may be passed on stack, we need to align the stack frame when there is no tail call. Tested on Linux/i686 and Linux/x86-64. gcc/ Backport from mainline PR target/83330 * config/i386/i386.c (ix86_function_arg_advance): Set outgoing_args_on_stack to true if there are outgoing arguments on stack. (ix86_function_arg): Likewise. (ix86_compute_frame_layout): Align stack frame if argument is passed on stack. * config/i386/i386.h (machine_function): Add outgoing_args_on_stack. gcc/testsuite/ Backport from mainline PR target/83330 * gcc.target/i386/pr83330.c: New test.
-rw-r--r--gcc/config/i386/i386.c19
-rw-r--r--gcc/config/i386/i386.h3
-rw-r--r--gcc/testsuite/gcc.target/i386/pr83330.c29
3 files changed, 49 insertions, 2 deletions
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 8a3782c0298..4cc59e164ed 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -9799,7 +9799,13 @@ ix86_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
/* For pointers passed in memory we expect bounds passed in Bounds
Table. */
if (!nregs)
- cum->bnds_in_bt = chkp_type_bounds_count (type);
+ {
+ /* Track if there are outgoing arguments on stack. */
+ if (cum->caller)
+ cfun->machine->outgoing_args_on_stack = true;
+
+ cum->bnds_in_bt = chkp_type_bounds_count (type);
+ }
}
/* Define where to put the arguments to a function.
@@ -10128,6 +10134,10 @@ ix86_function_arg (cumulative_args_t cum_v, machine_mode omode,
else
arg = function_arg_32 (cum, mode, omode, type, bytes, words);
+ /* Track if there are outgoing arguments on stack. */
+ if (arg == NULL_RTX && cum->caller)
+ cfun->machine->outgoing_args_on_stack = true;
+
return arg;
}
@@ -12557,11 +12567,16 @@ ix86_compute_frame_layout (struct ix86_frame *frame)
frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
offset += frame->va_arg_size;
- /* Align start of frame for local function. */
+ /* Align start of frame for local function. When a function call
+ is removed, it may become a leaf function. But if argument may
+ be passed on stack, we need to align the stack when there is no
+ tail call. */
if (stack_realign_fp
|| offset != frame->sse_reg_save_offset
|| size != 0
|| !crtl->is_leaf
+ || (!crtl->tail_call_emit
+ && cfun->machine->outgoing_args_on_stack)
|| cfun->calls_alloca
|| ix86_current_function_calls_tls_descriptor)
offset = ROUND_UP (offset, stack_alignment_needed);
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 9c776dc5172..7c651d7b944 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2570,6 +2570,9 @@ struct GTY(()) machine_function {
pass arguments and can be used for indirect sibcall. */
BOOL_BITFIELD arg_reg_available : 1;
+ /* Nonzero if the function places outgoing arguments on stack. */
+ BOOL_BITFIELD outgoing_args_on_stack : 1;
+
/* During prologue/epilogue generation, the current frame state.
Otherwise, the frame state at the end of the prologue. */
struct machine_frame_state fs;
diff --git a/gcc/testsuite/gcc.target/i386/pr83330.c b/gcc/testsuite/gcc.target/i386/pr83330.c
new file mode 100644
index 00000000000..9040168377a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr83330.c
@@ -0,0 +1,29 @@
+/* { dg-do run { target int128 } } */
+/* { dg-options "-O2 -fno-tree-dce -mno-push-args" } */
+
+typedef unsigned long long u64;
+typedef unsigned __int128 u128;
+
+u64 v;
+u64 g;
+
+u64 __attribute__ ((noinline, noclone))
+bar (u128 d, u64 e, u64 f, u64 g, u128 h)
+{
+ (void)d, (void)e, (void)f, (void)g, (void)h;
+ return 0;
+}
+
+static u64
+foo (void)
+{
+ (void)(v - bar (0, 0, 0, 0, 0));
+ return g;
+}
+
+int
+main (void)
+{
+ (void)foo ();
+ return 0;
+}