* [PATCH] x86: Properly check register CFA offset
@ 2017-07-26 16:14 H.J. Lu
2017-07-26 19:04 ` Uros Bizjak
0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2017-07-26 16:14 UTC (permalink / raw)
To: gcc-patches; +Cc: Uros Bizjak
X86 epilogue saves register at CFA offset. Since its location on stack
is computed as CFA - its CFA_OFFSET, CFA_OFFSET points the end of the
saved register location on stack. This patch updates sp_valid_at and
fp_valid_at to properly check register CFA offset.
Tested on x86-64. OK for trunk if there are no regressions on i686?
Thanks.
H.J.
--
gcc/
PR target/81563
* config/i386/i386.c (sp_valid_at): Properly check CFA offset.
(fp_valid_at): Likewise.
gcc/testsuite/
PR target/81563
* gcc.target/i386/pr81563.c: New test
---
gcc/config/i386/i386.c | 10 ++++++----
gcc/testsuite/gcc.target/i386/pr81563.c | 14 ++++++++++++++
2 files changed, 20 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr81563.c
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 084b4a6a0db..f1486ff3750 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -13102,24 +13102,26 @@ choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset)
return len;
}
-/* Determine if the stack pointer is valid for accessing the cfa_offset. */
+/* Determine if the stack pointer is valid for accessing the cfa_offset.
+ The register is saved at CFA - CFA_OFFSET. */
static inline bool
sp_valid_at (HOST_WIDE_INT cfa_offset)
{
const struct machine_frame_state &fs = cfun->machine->fs;
return fs.sp_valid && !(fs.sp_realigned
- && cfa_offset < fs.sp_realigned_offset);
+ && cfa_offset <= fs.sp_realigned_offset);
}
-/* Determine if the frame pointer is valid for accessing the cfa_offset. */
+/* Determine if the frame pointer is valid for accessing the cfa_offset.
+ The register is saved at CFA - CFA_OFFSET. */
static inline bool
fp_valid_at (HOST_WIDE_INT cfa_offset)
{
const struct machine_frame_state &fs = cfun->machine->fs;
return fs.fp_valid && !(fs.sp_valid && fs.sp_realigned
- && cfa_offset >= fs.sp_realigned_offset);
+ && cfa_offset > fs.sp_realigned_offset);
}
/* Choose a base register based upon alignment requested, speed and/or
diff --git a/gcc/testsuite/gcc.target/i386/pr81563.c b/gcc/testsuite/gcc.target/i386/pr81563.c
new file mode 100644
index 00000000000..ebfd583daf5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81563.c
@@ -0,0 +1,14 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-O2 -maccumulate-outgoing-args -mincoming-stack-boundary=2 -mpreferred-stack-boundary=3 -mregparm=3 -mtune-ctrl=epilogue_using_move" } */
+
+extern void bar (long long int, int);
+
+long long int
+fn1 (long long int x)
+{
+ bar (x, 1);
+ return x;
+}
+
+/* { dg-final { scan-assembler-times "movl\[\\t \]*-8\\(%ebp\\),\[\\t \]*%esi" 1 } } */
+/* { dg-final { scan-assembler-times "movl\[\\t \]*-4\\(%ebp\\),\[\\t \]*%edi" 1 } } */
--
2.13.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86: Properly check register CFA offset
2017-07-26 16:14 [PATCH] x86: Properly check register CFA offset H.J. Lu
@ 2017-07-26 19:04 ` Uros Bizjak
2017-07-26 19:15 ` H.J. Lu
0 siblings, 1 reply; 3+ messages in thread
From: Uros Bizjak @ 2017-07-26 19:04 UTC (permalink / raw)
To: H.J. Lu; +Cc: gcc-patches
On Wed, Jul 26, 2017 at 6:14 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>
> X86 epilogue saves register at CFA offset. Since its location on stack
> is computed as CFA - its CFA_OFFSET, CFA_OFFSET points the end of the
> saved register location on stack. This patch updates sp_valid_at and
> fp_valid_at to properly check register CFA offset.
>
> Tested on x86-64. OK for trunk if there are no regressions on i686?
>
> Thanks.
>
> H.J.
> --
> gcc/
>
> PR target/81563
> * config/i386/i386.c (sp_valid_at): Properly check CFA offset.
> (fp_valid_at): Likewise.
>
> gcc/testsuite/
>
> PR target/81563
> * gcc.target/i386/pr81563.c: New test
OK.
Thanks,
Uros.
> ---
> gcc/config/i386/i386.c | 10 ++++++----
> gcc/testsuite/gcc.target/i386/pr81563.c | 14 ++++++++++++++
> 2 files changed, 20 insertions(+), 4 deletions(-)
> create mode 100644 gcc/testsuite/gcc.target/i386/pr81563.c
>
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 084b4a6a0db..f1486ff3750 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -13102,24 +13102,26 @@ choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset)
> return len;
> }
>
> -/* Determine if the stack pointer is valid for accessing the cfa_offset. */
> +/* Determine if the stack pointer is valid for accessing the cfa_offset.
> + The register is saved at CFA - CFA_OFFSET. */
>
> static inline bool
> sp_valid_at (HOST_WIDE_INT cfa_offset)
> {
> const struct machine_frame_state &fs = cfun->machine->fs;
> return fs.sp_valid && !(fs.sp_realigned
> - && cfa_offset < fs.sp_realigned_offset);
> + && cfa_offset <= fs.sp_realigned_offset);
> }
>
> -/* Determine if the frame pointer is valid for accessing the cfa_offset. */
> +/* Determine if the frame pointer is valid for accessing the cfa_offset.
> + The register is saved at CFA - CFA_OFFSET. */
>
> static inline bool
> fp_valid_at (HOST_WIDE_INT cfa_offset)
> {
> const struct machine_frame_state &fs = cfun->machine->fs;
> return fs.fp_valid && !(fs.sp_valid && fs.sp_realigned
> - && cfa_offset >= fs.sp_realigned_offset);
> + && cfa_offset > fs.sp_realigned_offset);
> }
>
> /* Choose a base register based upon alignment requested, speed and/or
> diff --git a/gcc/testsuite/gcc.target/i386/pr81563.c b/gcc/testsuite/gcc.target/i386/pr81563.c
> new file mode 100644
> index 00000000000..ebfd583daf5
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr81563.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile { target ia32 } } */
> +/* { dg-options "-O2 -maccumulate-outgoing-args -mincoming-stack-boundary=2 -mpreferred-stack-boundary=3 -mregparm=3 -mtune-ctrl=epilogue_using_move" } */
> +
> +extern void bar (long long int, int);
> +
> +long long int
> +fn1 (long long int x)
> +{
> + bar (x, 1);
> + return x;
> +}
> +
> +/* { dg-final { scan-assembler-times "movl\[\\t \]*-8\\(%ebp\\),\[\\t \]*%esi" 1 } } */
> +/* { dg-final { scan-assembler-times "movl\[\\t \]*-4\\(%ebp\\),\[\\t \]*%edi" 1 } } */
> --
> 2.13.3
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86: Properly check register CFA offset
2017-07-26 19:04 ` Uros Bizjak
@ 2017-07-26 19:15 ` H.J. Lu
0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2017-07-26 19:15 UTC (permalink / raw)
To: Uros Bizjak; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 863 bytes --]
On Wed, Jul 26, 2017 at 12:04 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Wed, Jul 26, 2017 at 6:14 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>
>> X86 epilogue saves register at CFA offset. Since its location on stack
>> is computed as CFA - its CFA_OFFSET, CFA_OFFSET points the end of the
>> saved register location on stack. This patch updates sp_valid_at and
>> fp_valid_at to properly check register CFA offset.
>>
>> Tested on x86-64. OK for trunk if there are no regressions on i686?
>>
>> Thanks.
>>
>> H.J.
>> --
>> gcc/
>>
>> PR target/81563
>> * config/i386/i386.c (sp_valid_at): Properly check CFA offset.
>> (fp_valid_at): Likewise.
>>
>> gcc/testsuite/
>>
>> PR target/81563
>> * gcc.target/i386/pr81563.c: New test
>
> OK.
>
This is what I checked in with the updated commit log.
Thanks.
--
H.J.
[-- Attachment #2: 0001-x86-Properly-check-saved-register-CFA-offset.patch --]
[-- Type: text/x-patch, Size: 2922 bytes --]
From f7ccc9fc8419d08d8dbf9bd3ed3eec244196a6db Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 26 Jul 2017 09:06:22 -0700
Subject: [PATCH] x86: Properly check saved register CFA offset
X86 prologue saves register at CFA offset. Since its location on stack
is computed as CFA - its CFA_OFFSET, CFA_OFFSET points the end of the
saved register area on stack. This patch updates sp_valid_at and
fp_valid_at to properly check saved register CFA offset.
gcc/
PR target/81563
* config/i386/i386.c (sp_valid_at): Properly check CFA offset.
(fp_valid_at): Likewise.
gcc/testsuite/
PR target/81563
* gcc.target/i386/pr81563.c: New test
---
gcc/config/i386/i386.c | 10 ++++++----
gcc/testsuite/gcc.target/i386/pr81563.c | 14 ++++++++++++++
2 files changed, 20 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr81563.c
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 084b4a6a0db..f1486ff3750 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -13102,24 +13102,26 @@ choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset)
return len;
}
-/* Determine if the stack pointer is valid for accessing the cfa_offset. */
+/* Determine if the stack pointer is valid for accessing the cfa_offset.
+ The register is saved at CFA - CFA_OFFSET. */
static inline bool
sp_valid_at (HOST_WIDE_INT cfa_offset)
{
const struct machine_frame_state &fs = cfun->machine->fs;
return fs.sp_valid && !(fs.sp_realigned
- && cfa_offset < fs.sp_realigned_offset);
+ && cfa_offset <= fs.sp_realigned_offset);
}
-/* Determine if the frame pointer is valid for accessing the cfa_offset. */
+/* Determine if the frame pointer is valid for accessing the cfa_offset.
+ The register is saved at CFA - CFA_OFFSET. */
static inline bool
fp_valid_at (HOST_WIDE_INT cfa_offset)
{
const struct machine_frame_state &fs = cfun->machine->fs;
return fs.fp_valid && !(fs.sp_valid && fs.sp_realigned
- && cfa_offset >= fs.sp_realigned_offset);
+ && cfa_offset > fs.sp_realigned_offset);
}
/* Choose a base register based upon alignment requested, speed and/or
diff --git a/gcc/testsuite/gcc.target/i386/pr81563.c b/gcc/testsuite/gcc.target/i386/pr81563.c
new file mode 100644
index 00000000000..ebfd583daf5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr81563.c
@@ -0,0 +1,14 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-O2 -maccumulate-outgoing-args -mincoming-stack-boundary=2 -mpreferred-stack-boundary=3 -mregparm=3 -mtune-ctrl=epilogue_using_move" } */
+
+extern void bar (long long int, int);
+
+long long int
+fn1 (long long int x)
+{
+ bar (x, 1);
+ return x;
+}
+
+/* { dg-final { scan-assembler-times "movl\[\\t \]*-8\\(%ebp\\),\[\\t \]*%esi" 1 } } */
+/* { dg-final { scan-assembler-times "movl\[\\t \]*-4\\(%ebp\\),\[\\t \]*%edi" 1 } } */
--
2.13.3
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-26 19:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-26 16:14 [PATCH] x86: Properly check register CFA offset H.J. Lu
2017-07-26 19:04 ` Uros Bizjak
2017-07-26 19:15 ` 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).