* [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack
@ 2017-07-06 19:08 H.J. Lu
2017-07-06 22:14 ` H.J. Lu
0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2017-07-06 19:08 UTC (permalink / raw)
To: gcc-patches; +Cc: Uros Bizjak
Since DRAP is needed only if there are outgoing arguments on stack, we
should track outgoing arguments on stack and avoid setting need_drap to
true when there are no outgoing arguments on stack.
Tested on i686 and x86-64 with SSE2, AVX and AVX2. There is no
regression. OK for trunk?
H.J.
---
gcc/
PR target/81313
* 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_get_drap_rtx): Use DRAP only if there are outgoing
arguments on stack and ACCUMULATE_OUTGOING_ARGS is false.
* config/i386/i386.h (machine_function): Add
outgoing_args_on_stack.
gcc/testsuite/
PR target/81313
* gcc.target/i386/pr81313-1.c: New test.
* gcc.target/i386/pr81313-2.c: Likewise.
* gcc.target/i386/pr81313-3.c: Likewise.
* gcc.target/i386/pr81313-4.c: Likewise.
---
gcc/config/i386/i386.c | 18 ++++++++++++++++--
gcc/config/i386/i386.h | 3 +++
gcc/testsuite/gcc.target/i386/pr81313-1.c | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr81313-2.c | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr81313-3.c | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr81313-4.c | 12 ++++++++++++
6 files changed, 67 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr81313-1.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr81313-2.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr81313-3.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr81313-4.c
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 1a8a3a3..9b64d50 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -10143,7 +10143,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.
@@ -10473,6 +10479,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)
+ cfun->machine->outgoing_args_on_stack = true;
+
return arg;
}
@@ -13646,7 +13656,11 @@ ix86_update_stack_boundary (void)
static rtx
ix86_get_drap_rtx (void)
{
- if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
+ /* We must use DRAP if there are outgoing arguments on stack and
+ ACCUMULATE_OUTGOING_ARGS is false. */
+ if (ix86_force_drap
+ || (cfun->machine->outgoing_args_on_stack
+ && !ACCUMULATE_OUTGOING_ARGS))
crtl->need_drap = true;
if (stack_realign_drap)
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 08243c1..a2ae9b4 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2657,6 +2657,9 @@ struct GTY(()) machine_function {
frame pointer.) */
unsigned int call_ms2sysv_extra_regs:3;
+ /* 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/pr81313-1.c b/gcc/testsuite/gcc.target/i386/pr81313-1.c
new file mode 100644
index 0000000..f765003
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81313-1.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mno-accumulate-outgoing-args -mincoming-stack-boundary=4 -mpreferred-stack-boundary=6" } */
+
+extern void foo (void);
+
+void
+bar (void)
+{
+ foo ();
+}
+
+/* { dg-final { scan-assembler-not "lea\[lq\]?\[\\t \]*\[0-9\]*\\(%\[er\]sp\\)" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr81313-2.c b/gcc/testsuite/gcc.target/i386/pr81313-2.c
new file mode 100644
index 0000000..2cdc645
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81313-2.c
@@ -0,0 +1,12 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-O2 -mno-accumulate-outgoing-args -mincoming-stack-boundary=4 -mpreferred-stack-boundary=6 -mno-iamcu" } */
+
+extern void foo (int, int, int);
+
+void
+bar (void)
+{
+ foo (1, 2, 3);
+}
+
+/* { dg-final { scan-assembler "lea\[l\]?\[\\t \]*\[0-9\]*\\(%esp\\)" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr81313-3.c b/gcc/testsuite/gcc.target/i386/pr81313-3.c
new file mode 100644
index 0000000..14bd708
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81313-3.c
@@ -0,0 +1,12 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-O2 -mno-accumulate-outgoing-args -mincoming-stack-boundary=4 -mpreferred-stack-boundary=6" } */
+
+extern void foo (int, int, int) __attribute__ ((regparm(3)));
+
+void
+bar (void)
+{
+ foo (1, 2, 3);
+}
+
+/* { dg-final { scan-assembler-not "lea\[l\]?\[\\t \]*\[0-9\]*\\(%esp\\)" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr81313-4.c b/gcc/testsuite/gcc.target/i386/pr81313-4.c
new file mode 100644
index 0000000..bad0b3c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81313-4.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mno-accumulate-outgoing-args -mincoming-stack-boundary=4 -mpreferred-stack-boundary=6" } */
+
+extern void foo (int, int, int, int, int, int, int);
+
+void
+bar (void)
+{
+ foo (1, 2, 3, 4, 5, 6, 7);
+}
+
+/* { dg-final { scan-assembler "lea\[lq\]?\[\\t \]*\[0-9\]*\\(%\[er\]sp\\)" } } */
--
2.9.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack
2017-07-06 19:08 [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack H.J. Lu
@ 2017-07-06 22:14 ` H.J. Lu
2017-07-09 18:19 ` Uros Bizjak
0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2017-07-06 22:14 UTC (permalink / raw)
To: GCC Patches; +Cc: Uros Bizjak
[-- Attachment #1: Type: text/plain, Size: 1452 bytes --]
On Thu, Jul 6, 2017 at 12:08 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Since DRAP is needed only if there are outgoing arguments on stack, we
> should track outgoing arguments on stack and avoid setting need_drap to
> true when there are no outgoing arguments on stack.
>
> Tested on i686 and x86-64 with SSE2, AVX and AVX2. There is no
> regression. OK for trunk?
>
> H.J.
> ---
> gcc/
>
> PR target/81313
> * 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_get_drap_rtx): Use DRAP only if there are outgoing
> arguments on stack and ACCUMULATE_OUTGOING_ARGS is false.
> * config/i386/i386.h (machine_function): Add
> outgoing_args_on_stack.
>
> @@ -10473,6 +10479,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)
> + cfun->machine->outgoing_args_on_stack = true;
This should be
+ /* Track if there are outgoing arguments on stack. */
+ if (arg == NULL_RTX && cum->caller)
+ cfun->machine->outgoing_args_on_stack = true;
to check outgoing arguments for caller here.
> return arg;
> }
>
>
I am testing updated patch with a new testcase.
--
H.J.
[-- Attachment #2: 0001-x86-Use-DRAP-only-if-there-are-outgoing-arguments-on.patch --]
[-- Type: text/x-patch, Size: 6688 bytes --]
From 4d02c433206790e0ae7de4e91c0f412f9bdac7e8 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 6 Jul 2017 08:58:46 -0700
Subject: [PATCH] x86: Use DRAP only if there are outgoing arguments on stack
Since DRAP is needed only if there are outgoing arguments on stack, we
should track outgoing arguments on stack and avoid setting need_drap to
true when there are no outgoing arguments on stack.
gcc/
PR target/81313
* 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_get_drap_rtx): Use DRAP only if there are outgoing
arguments on stack and ACCUMULATE_OUTGOING_ARGS is false.
* config/i386/i386.h (machine_function): Add
outgoing_args_on_stack.
gcc/testsuite/
PR target/81313
* gcc.target/i386/pr81313-1.c: New test.
* gcc.target/i386/pr81313-2.c: Likewise.
* gcc.target/i386/pr81313-3.c: Likewise.
* gcc.target/i386/pr81313-4.c: Likewise.
* gcc.target/i386/pr81313-5.c: Likewise.
---
gcc/config/i386/i386.c | 18 ++++++++++++++++--
gcc/config/i386/i386.h | 3 +++
gcc/testsuite/gcc.target/i386/pr81313-1.c | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr81313-2.c | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr81313-3.c | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr81313-4.c | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr81313-5.c | 12 ++++++++++++
7 files changed, 79 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr81313-1.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr81313-2.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr81313-3.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr81313-4.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr81313-5.c
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 1a8a3a3..b041524 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -10143,7 +10143,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.
@@ -10473,6 +10479,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;
}
@@ -13646,7 +13656,11 @@ ix86_update_stack_boundary (void)
static rtx
ix86_get_drap_rtx (void)
{
- if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
+ /* We must use DRAP if there are outgoing arguments on stack and
+ ACCUMULATE_OUTGOING_ARGS is false. */
+ if (ix86_force_drap
+ || (cfun->machine->outgoing_args_on_stack
+ && !ACCUMULATE_OUTGOING_ARGS))
crtl->need_drap = true;
if (stack_realign_drap)
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 08243c1..a2ae9b4 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2657,6 +2657,9 @@ struct GTY(()) machine_function {
frame pointer.) */
unsigned int call_ms2sysv_extra_regs:3;
+ /* 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/pr81313-1.c b/gcc/testsuite/gcc.target/i386/pr81313-1.c
new file mode 100644
index 0000000..f765003
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81313-1.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mno-accumulate-outgoing-args -mincoming-stack-boundary=4 -mpreferred-stack-boundary=6" } */
+
+extern void foo (void);
+
+void
+bar (void)
+{
+ foo ();
+}
+
+/* { dg-final { scan-assembler-not "lea\[lq\]?\[\\t \]*\[0-9\]*\\(%\[er\]sp\\)" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr81313-2.c b/gcc/testsuite/gcc.target/i386/pr81313-2.c
new file mode 100644
index 0000000..2cdc645
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81313-2.c
@@ -0,0 +1,12 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-O2 -mno-accumulate-outgoing-args -mincoming-stack-boundary=4 -mpreferred-stack-boundary=6 -mno-iamcu" } */
+
+extern void foo (int, int, int);
+
+void
+bar (void)
+{
+ foo (1, 2, 3);
+}
+
+/* { dg-final { scan-assembler "lea\[l\]?\[\\t \]*\[0-9\]*\\(%esp\\)" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr81313-3.c b/gcc/testsuite/gcc.target/i386/pr81313-3.c
new file mode 100644
index 0000000..9c1b232
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81313-3.c
@@ -0,0 +1,12 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-O2 -mno-accumulate-outgoing-args -mincoming-stack-boundary=4 -mpreferred-stack-boundary=6" } */
+
+extern void foo (int, int, int) __attribute__ ((regparm(3)));
+
+void
+bar (int i1, int i2, int i3, int i4)
+{
+ foo (i1, i2, i3);
+}
+
+/* { dg-final { scan-assembler-not "lea\[l\]?\[\\t \]*\[0-9\]*\\(%esp\\)" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr81313-4.c b/gcc/testsuite/gcc.target/i386/pr81313-4.c
new file mode 100644
index 0000000..bad0b3c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81313-4.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mno-accumulate-outgoing-args -mincoming-stack-boundary=4 -mpreferred-stack-boundary=6" } */
+
+extern void foo (int, int, int, int, int, int, int);
+
+void
+bar (void)
+{
+ foo (1, 2, 3, 4, 5, 6, 7);
+}
+
+/* { dg-final { scan-assembler "lea\[lq\]?\[\\t \]*\[0-9\]*\\(%\[er\]sp\\)" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr81313-5.c b/gcc/testsuite/gcc.target/i386/pr81313-5.c
new file mode 100644
index 0000000..51a543c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81313-5.c
@@ -0,0 +1,12 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2 -mno-accumulate-outgoing-args -mincoming-stack-boundary=4 -mpreferred-stack-boundary=6" } */
+
+extern void foo (int, int, int, int, int, int);
+
+void
+bar (int i1, int i2, int i3, int i4, int i5, int i6, int i7)
+{
+ foo (i1, i2, i3, i4, i5, i6);
+}
+
+/* { dg-final { scan-assembler-not "lea\[lq\]?\[\\t \]*\[0-9\]*\\(%\[er\]sp\\)" } } */
--
2.9.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack
2017-07-06 22:14 ` H.J. Lu
@ 2017-07-09 18:19 ` Uros Bizjak
2017-07-09 18:29 ` H.J. Lu
0 siblings, 1 reply; 8+ messages in thread
From: Uros Bizjak @ 2017-07-09 18:19 UTC (permalink / raw)
To: H.J. Lu; +Cc: GCC Patches
On Fri, Jul 7, 2017 at 12:14 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Jul 6, 2017 at 12:08 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>> Since DRAP is needed only if there are outgoing arguments on stack, we
>> should track outgoing arguments on stack and avoid setting need_drap to
>> true when there are no outgoing arguments on stack.
>>
>> Tested on i686 and x86-64 with SSE2, AVX and AVX2. There is no
>> regression. OK for trunk?
>>
>> H.J.
>> ---
>> gcc/
>>
>> PR target/81313
>> * 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_get_drap_rtx): Use DRAP only if there are outgoing
>> arguments on stack and ACCUMULATE_OUTGOING_ARGS is false.
>> * config/i386/i386.h (machine_function): Add
>> outgoing_args_on_stack.
>>
>> @@ -10473,6 +10479,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)
>> + cfun->machine->outgoing_args_on_stack = true;
>
> This should be
>
> + /* Track if there are outgoing arguments on stack. */
> + if (arg == NULL_RTX && cum->caller)
> + cfun->machine->outgoing_args_on_stack = true;
>
> to check outgoing arguments for caller here.
>
>> return arg;
>> }
>>
>>
>
> I am testing updated patch with a new testcase.
Updated patch LGTM.
OK for mainline.
Thanks,
Uros.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack
2017-07-09 18:19 ` Uros Bizjak
@ 2017-07-09 18:29 ` H.J. Lu
2017-07-09 18:57 ` Uros Bizjak
0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2017-07-09 18:29 UTC (permalink / raw)
To: Uros Bizjak; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 2367 bytes --]
On Sun, Jul 9, 2017 at 11:19 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Fri, Jul 7, 2017 at 12:14 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Thu, Jul 6, 2017 at 12:08 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>> Since DRAP is needed only if there are outgoing arguments on stack, we
>>> should track outgoing arguments on stack and avoid setting need_drap to
>>> true when there are no outgoing arguments on stack.
>>>
>>> Tested on i686 and x86-64 with SSE2, AVX and AVX2. There is no
>>> regression. OK for trunk?
>>>
>>> H.J.
>>> ---
>>> gcc/
>>>
>>> PR target/81313
>>> * 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_get_drap_rtx): Use DRAP only if there are outgoing
>>> arguments on stack and ACCUMULATE_OUTGOING_ARGS is false.
>>> * config/i386/i386.h (machine_function): Add
>>> outgoing_args_on_stack.
>>>
>>> @@ -10473,6 +10479,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)
>>> + cfun->machine->outgoing_args_on_stack = true;
>>
>> This should be
>>
>> + /* Track if there are outgoing arguments on stack. */
>> + if (arg == NULL_RTX && cum->caller)
>> + cfun->machine->outgoing_args_on_stack = true;
>>
>> to check outgoing arguments for caller here.
>>
>>> return arg;
>>> }
>>>
>>>
>>
>> I am testing updated patch with a new testcase.
>
> Updated patch LGTM.
>
> OK for mainline.
Done. My patch will cause
FAIL: gcc.dg/stack-layout-dynamic-1.c
since on x86, now stack realignment is done with
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
andl $-65536, %esp
instead of
.cfi_startproc
pushl %edi
.cfi_def_cfa_offset 8
.cfi_offset 7, -8
leal 8(%esp), %edi
.cfi_def_cfa 7, 0
andl $-65536, %esp
pushl -4(%edi)
pushl %ebp
.cfi_escape 0x10,0x5,0x2,0x75,0
movl %esp, %ebp
PR target/81313
* gcc.dg/stack-layout-dynamic-1.c (dg-options): Add -mregparm=3
for ia32.
Don't expect cfi_escape and expect cfi_def_cfa_register on x86.
OK for trunk?
Thanks.
--
H.J.
[-- Attachment #2: 0001-x86-Update-gcc.dg-stack-layout-dynamic-1.c.patch --]
[-- Type: text/x-patch, Size: 2044 bytes --]
From 810ce19512c1e55095ac33c5ebd54bb74e47049a Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 6 Jul 2017 10:56:57 -0700
Subject: [PATCH] x86: Update gcc.dg/stack-layout-dynamic-1.c
On x86, since stack realignment is done with
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
andl $-65536, %esp
it is preferred to have .cfi_def_cfa_register, instead of
.cfi_startproc
pushl %edi
.cfi_def_cfa_offset 8
.cfi_offset 7, -8
leal 8(%esp), %edi
.cfi_def_cfa 7, 0
andl $-65536, %esp
pushl -4(%edi)
pushl %ebp
.cfi_escape 0x10,0x5,0x2,0x75,0
movl %esp, %ebp
PR target/81313
* gcc.dg/stack-layout-dynamic-1.c (dg-options): Add -mregparm=3
for ia32.
Don't expect cfi_escape and expect cfi_def_cfa_register on x86.
---
gcc/testsuite/gcc.dg/stack-layout-dynamic-1.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/gcc/testsuite/gcc.dg/stack-layout-dynamic-1.c b/gcc/testsuite/gcc.dg/stack-layout-dynamic-1.c
index 9f2d37d..c08cd9d 100644
--- a/gcc/testsuite/gcc.dg/stack-layout-dynamic-1.c
+++ b/gcc/testsuite/gcc.dg/stack-layout-dynamic-1.c
@@ -2,6 +2,7 @@
in one pass together with normal local variables. */
/* { dg-do compile } */
/* { dg-options "-O0 -fomit-frame-pointer" } */
+/* { dg-options "-O0 -fomit-frame-pointer -mregparm=3" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
/* { dg-require-effective-target ptr32plus } */
extern void bar (void *, void *, void *);
@@ -12,4 +13,6 @@ void foo (void)
__attribute__ ((aligned(32768))) char runtime_aligned_2[1024];
bar (&i, &runtime_aligned_1, &runtime_aligned_2);
}
-/* { dg-final { scan-assembler-not "cfi_def_cfa_register" } } */
+/* { dg-final { scan-assembler-not "cfi_escape" { target i?86-*-* x86_64-*-* } } } */
+/* { dg-final { scan-assembler-not "cfi_def_cfa_register" { target { ! { { i?86-*-* } || { x86_64-*-* } } } } } } */
+/* { dg-final { scan-assembler "cfi_def_cfa_register" { target i?86-*-* x86_64-*-* } } } */
--
2.9.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack
2017-07-09 18:29 ` H.J. Lu
@ 2017-07-09 18:57 ` Uros Bizjak
2017-07-09 19:06 ` H.J. Lu
2017-07-09 20:53 ` H.J. Lu
0 siblings, 2 replies; 8+ messages in thread
From: Uros Bizjak @ 2017-07-09 18:57 UTC (permalink / raw)
To: H.J. Lu; +Cc: GCC Patches
On Sun, Jul 9, 2017 at 8:29 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sun, Jul 9, 2017 at 11:19 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>> On Fri, Jul 7, 2017 at 12:14 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Thu, Jul 6, 2017 at 12:08 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>> Since DRAP is needed only if there are outgoing arguments on stack, we
>>>> should track outgoing arguments on stack and avoid setting need_drap to
>>>> true when there are no outgoing arguments on stack.
>>>>
>>>> Tested on i686 and x86-64 with SSE2, AVX and AVX2. There is no
>>>> regression. OK for trunk?
>>>>
>>>> H.J.
>>>> ---
>>>> gcc/
>>>>
>>>> PR target/81313
>>>> * 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_get_drap_rtx): Use DRAP only if there are outgoing
>>>> arguments on stack and ACCUMULATE_OUTGOING_ARGS is false.
>>>> * config/i386/i386.h (machine_function): Add
>>>> outgoing_args_on_stack.
>>>>
>>>> @@ -10473,6 +10479,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)
>>>> + cfun->machine->outgoing_args_on_stack = true;
>>>
>>> This should be
>>>
>>> + /* Track if there are outgoing arguments on stack. */
>>> + if (arg == NULL_RTX && cum->caller)
>>> + cfun->machine->outgoing_args_on_stack = true;
>>>
>>> to check outgoing arguments for caller here.
>>>
>>>> return arg;
>>>> }
>>>>
>>>>
>>>
>>> I am testing updated patch with a new testcase.
>>
>> Updated patch LGTM.
>>
>> OK for mainline.
>
> Done. My patch will cause
>
> FAIL: gcc.dg/stack-layout-dynamic-1.c
>
> since on x86, now stack realignment is done with
>
> .cfi_startproc
> pushl %ebp
> .cfi_def_cfa_offset 8
> .cfi_offset 5, -8
> movl %esp, %ebp
> .cfi_def_cfa_register 5
> andl $-65536, %esp
>
> instead of
>
> .cfi_startproc
> pushl %edi
> .cfi_def_cfa_offset 8
> .cfi_offset 7, -8
> leal 8(%esp), %edi
> .cfi_def_cfa 7, 0
> andl $-65536, %esp
> pushl -4(%edi)
> pushl %ebp
> .cfi_escape 0x10,0x5,0x2,0x75,0
> movl %esp, %ebp
>
> PR target/81313
> * gcc.dg/stack-layout-dynamic-1.c (dg-options): Add -mregparm=3
> for ia32.
> Don't expect cfi_escape and expect cfi_def_cfa_register on x86.
>
> OK for trunk?
Better use something like:
--cut here--
Index: stack-layout-dynamic-1.c
===================================================================
--- stack-layout-dynamic-1.c (revision 250084)
+++ stack-layout-dynamic-1.c (working copy)
@@ -4,12 +4,12 @@
/* { dg-options "-O0 -fomit-frame-pointer" } */
/* { dg-require-effective-target ptr32plus } */
-extern void bar (void *, void *, void *);
+extern void bar (void *,void *, void *, void *, void *, void *, void *);
void foo (void)
{
- int i;
+ int i, j, k, l, m;
__attribute__ ((aligned(65536))) char runtime_aligned_1[512];
__attribute__ ((aligned(32768))) char runtime_aligned_2[1024];
- bar (&i, &runtime_aligned_1, &runtime_aligned_2);
+ bar (&i, &j, &k, &l, &m, &runtime_aligned_1, &runtime_aligned_2);
}
/* { dg-final { scan-assembler-not "cfi_def_cfa_register" } } */
--cut here--
so the testcase will suppress new optimization and test what it was
intended to test also on x86_64.
Uros.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack
2017-07-09 18:57 ` Uros Bizjak
@ 2017-07-09 19:06 ` H.J. Lu
2017-07-09 19:12 ` Uros Bizjak
2017-07-09 20:53 ` H.J. Lu
1 sibling, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2017-07-09 19:06 UTC (permalink / raw)
To: Uros Bizjak; +Cc: GCC Patches
On Sun, Jul 9, 2017 at 11:57 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Sun, Jul 9, 2017 at 8:29 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Sun, Jul 9, 2017 at 11:19 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>>> On Fri, Jul 7, 2017 at 12:14 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Thu, Jul 6, 2017 at 12:08 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>> Since DRAP is needed only if there are outgoing arguments on stack, we
>>>>> should track outgoing arguments on stack and avoid setting need_drap to
>>>>> true when there are no outgoing arguments on stack.
>>>>>
>>>>> Tested on i686 and x86-64 with SSE2, AVX and AVX2. There is no
>>>>> regression. OK for trunk?
>>>>>
>>>>> H.J.
>>>>> ---
>>>>> gcc/
>>>>>
>>>>> PR target/81313
>>>>> * 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_get_drap_rtx): Use DRAP only if there are outgoing
>>>>> arguments on stack and ACCUMULATE_OUTGOING_ARGS is false.
>>>>> * config/i386/i386.h (machine_function): Add
>>>>> outgoing_args_on_stack.
>>>>>
>>>>> @@ -10473,6 +10479,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)
>>>>> + cfun->machine->outgoing_args_on_stack = true;
>>>>
>>>> This should be
>>>>
>>>> + /* Track if there are outgoing arguments on stack. */
>>>> + if (arg == NULL_RTX && cum->caller)
>>>> + cfun->machine->outgoing_args_on_stack = true;
>>>>
>>>> to check outgoing arguments for caller here.
>>>>
>>>>> return arg;
>>>>> }
>>>>>
>>>>>
>>>>
>>>> I am testing updated patch with a new testcase.
>>>
>>> Updated patch LGTM.
>>>
>>> OK for mainline.
>>
>> Done. My patch will cause
>>
>> FAIL: gcc.dg/stack-layout-dynamic-1.c
>>
>> since on x86, now stack realignment is done with
>>
>> .cfi_startproc
>> pushl %ebp
>> .cfi_def_cfa_offset 8
>> .cfi_offset 5, -8
>> movl %esp, %ebp
>> .cfi_def_cfa_register 5
>> andl $-65536, %esp
>>
>> instead of
>>
>> .cfi_startproc
>> pushl %edi
>> .cfi_def_cfa_offset 8
>> .cfi_offset 7, -8
>> leal 8(%esp), %edi
>> .cfi_def_cfa 7, 0
>> andl $-65536, %esp
>> pushl -4(%edi)
>> pushl %ebp
>> .cfi_escape 0x10,0x5,0x2,0x75,0
>> movl %esp, %ebp
>>
>> PR target/81313
>> * gcc.dg/stack-layout-dynamic-1.c (dg-options): Add -mregparm=3
>> for ia32.
>> Don't expect cfi_escape and expect cfi_def_cfa_register on x86.
>>
>> OK for trunk?
>
> Better use something like:
>
> --cut here--
> Index: stack-layout-dynamic-1.c
> ===================================================================
> --- stack-layout-dynamic-1.c (revision 250084)
> +++ stack-layout-dynamic-1.c (working copy)
> @@ -4,12 +4,12 @@
> /* { dg-options "-O0 -fomit-frame-pointer" } */
> /* { dg-require-effective-target ptr32plus } */
>
> -extern void bar (void *, void *, void *);
> +extern void bar (void *,void *, void *, void *, void *, void *, void *);
> void foo (void)
> {
> - int i;
> + int i, j, k, l, m;
> __attribute__ ((aligned(65536))) char runtime_aligned_1[512];
> __attribute__ ((aligned(32768))) char runtime_aligned_2[1024];
> - bar (&i, &runtime_aligned_1, &runtime_aligned_2);
> + bar (&i, &j, &k, &l, &m, &runtime_aligned_1, &runtime_aligned_2);
> }
> /* { dg-final { scan-assembler-not "cfi_def_cfa_register" } } */
> --cut here--
>
> so the testcase will suppress new optimization and test what it was
> intended to test also on x86_64.
I will give it a try.
BTW, gcc.target/i386/pr59501-3a.c will fail the same way as
gcc.target/i386/pr59501-4a.c now since -mno-accumulate-outgoing-arg
works the same as -maccumulate-outgoing-args. A patch is posted at:
https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00400.html
to fix it.
--
H.J.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack
2017-07-09 19:06 ` H.J. Lu
@ 2017-07-09 19:12 ` Uros Bizjak
0 siblings, 0 replies; 8+ messages in thread
From: Uros Bizjak @ 2017-07-09 19:12 UTC (permalink / raw)
To: H.J. Lu; +Cc: GCC Patches
On Sun, Jul 9, 2017 at 9:06 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> PR target/81313
>>> * gcc.dg/stack-layout-dynamic-1.c (dg-options): Add -mregparm=3
>>> for ia32.
>>> Don't expect cfi_escape and expect cfi_def_cfa_register on x86.
>>>
>>> OK for trunk?
>>
>> Better use something like:
>>
>> --cut here--
>> Index: stack-layout-dynamic-1.c
>> ===================================================================
>> --- stack-layout-dynamic-1.c (revision 250084)
>> +++ stack-layout-dynamic-1.c (working copy)
>> @@ -4,12 +4,12 @@
>> /* { dg-options "-O0 -fomit-frame-pointer" } */
>> /* { dg-require-effective-target ptr32plus } */
>>
>> -extern void bar (void *, void *, void *);
>> +extern void bar (void *,void *, void *, void *, void *, void *, void *);
>> void foo (void)
>> {
>> - int i;
>> + int i, j, k, l, m;
>> __attribute__ ((aligned(65536))) char runtime_aligned_1[512];
>> __attribute__ ((aligned(32768))) char runtime_aligned_2[1024];
>> - bar (&i, &runtime_aligned_1, &runtime_aligned_2);
>> + bar (&i, &j, &k, &l, &m, &runtime_aligned_1, &runtime_aligned_2);
>> }
>> /* { dg-final { scan-assembler-not "cfi_def_cfa_register" } } */
>> --cut here--
>>
>> so the testcase will suppress new optimization and test what it was
>> intended to test also on x86_64.
>
> I will give it a try.
>
> BTW, gcc.target/i386/pr59501-3a.c will fail the same way as
> gcc.target/i386/pr59501-4a.c now since -mno-accumulate-outgoing-arg
> works the same as -maccumulate-outgoing-args. A patch is posted at:
>
> https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00400.html
>
> to fix it.
The referred patch enhances Jakubs PR 59501 patch, I'll wait for his
comments on your patch.
Uros.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack
2017-07-09 18:57 ` Uros Bizjak
2017-07-09 19:06 ` H.J. Lu
@ 2017-07-09 20:53 ` H.J. Lu
1 sibling, 0 replies; 8+ messages in thread
From: H.J. Lu @ 2017-07-09 20:53 UTC (permalink / raw)
To: Uros Bizjak; +Cc: GCC Patches
On Sun, Jul 9, 2017 at 11:57 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Sun, Jul 9, 2017 at 8:29 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Sun, Jul 9, 2017 at 11:19 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>>> On Fri, Jul 7, 2017 at 12:14 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Thu, Jul 6, 2017 at 12:08 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>> Since DRAP is needed only if there are outgoing arguments on stack, we
>>>>> should track outgoing arguments on stack and avoid setting need_drap to
>>>>> true when there are no outgoing arguments on stack.
>>>>>
>>>>> Tested on i686 and x86-64 with SSE2, AVX and AVX2. There is no
>>>>> regression. OK for trunk?
>>>>>
>>>>> H.J.
>>>>> ---
>>>>> gcc/
>>>>>
>>>>> PR target/81313
>>>>> * 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_get_drap_rtx): Use DRAP only if there are outgoing
>>>>> arguments on stack and ACCUMULATE_OUTGOING_ARGS is false.
>>>>> * config/i386/i386.h (machine_function): Add
>>>>> outgoing_args_on_stack.
>>>>>
>>>>> @@ -10473,6 +10479,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)
>>>>> + cfun->machine->outgoing_args_on_stack = true;
>>>>
>>>> This should be
>>>>
>>>> + /* Track if there are outgoing arguments on stack. */
>>>> + if (arg == NULL_RTX && cum->caller)
>>>> + cfun->machine->outgoing_args_on_stack = true;
>>>>
>>>> to check outgoing arguments for caller here.
>>>>
>>>>> return arg;
>>>>> }
>>>>>
>>>>>
>>>>
>>>> I am testing updated patch with a new testcase.
>>>
>>> Updated patch LGTM.
>>>
>>> OK for mainline.
>>
>> Done. My patch will cause
>>
>> FAIL: gcc.dg/stack-layout-dynamic-1.c
>>
>> since on x86, now stack realignment is done with
>>
>> .cfi_startproc
>> pushl %ebp
>> .cfi_def_cfa_offset 8
>> .cfi_offset 5, -8
>> movl %esp, %ebp
>> .cfi_def_cfa_register 5
>> andl $-65536, %esp
>>
>> instead of
>>
>> .cfi_startproc
>> pushl %edi
>> .cfi_def_cfa_offset 8
>> .cfi_offset 7, -8
>> leal 8(%esp), %edi
>> .cfi_def_cfa 7, 0
>> andl $-65536, %esp
>> pushl -4(%edi)
>> pushl %ebp
>> .cfi_escape 0x10,0x5,0x2,0x75,0
>> movl %esp, %ebp
>>
>> PR target/81313
>> * gcc.dg/stack-layout-dynamic-1.c (dg-options): Add -mregparm=3
>> for ia32.
>> Don't expect cfi_escape and expect cfi_def_cfa_register on x86.
>>
>> OK for trunk?
>
> Better use something like:
>
> --cut here--
> Index: stack-layout-dynamic-1.c
> ===================================================================
> --- stack-layout-dynamic-1.c (revision 250084)
> +++ stack-layout-dynamic-1.c (working copy)
> @@ -4,12 +4,12 @@
> /* { dg-options "-O0 -fomit-frame-pointer" } */
> /* { dg-require-effective-target ptr32plus } */
>
> -extern void bar (void *, void *, void *);
> +extern void bar (void *,void *, void *, void *, void *, void *, void *);
> void foo (void)
> {
> - int i;
> + int i, j, k, l, m;
> __attribute__ ((aligned(65536))) char runtime_aligned_1[512];
> __attribute__ ((aligned(32768))) char runtime_aligned_2[1024];
> - bar (&i, &runtime_aligned_1, &runtime_aligned_2);
> + bar (&i, &j, &k, &l, &m, &runtime_aligned_1, &runtime_aligned_2);
> }
> /* { dg-final { scan-assembler-not "cfi_def_cfa_register" } } */
> --cut here--
>
> so the testcase will suppress new optimization and test what it was
> intended to test also on x86_64.
>
Yes, it works. Can you check it in?
Thanks.
--
H.J.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-07-09 20:53 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-06 19:08 [PATCH] PR target/81313: Use DRAP only if there are outgoing arguments on stack H.J. Lu
2017-07-06 22:14 ` H.J. Lu
2017-07-09 18:19 ` Uros Bizjak
2017-07-09 18:29 ` H.J. Lu
2017-07-09 18:57 ` Uros Bizjak
2017-07-09 19:06 ` H.J. Lu
2017-07-09 19:12 ` Uros Bizjak
2017-07-09 20:53 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).