i386: Check red zone size in push peephole2

Message ID 20171011011649.GA4196@gmail.com
State New
Headers show
Series
  • i386: Check red zone size in push peephole2
Related show

Commit Message

H.J. Lu Oct. 11, 2017, 1:16 a.m.
Check red zone size, instead of if red zone is available, in push
peephole2s.

Tested on i686 and x86-64.  OK for master?


H.J.
---
gcc/

	PR target/82499
	* config/i386/i386.h (x86_red_zone_size): New.
	* config/i386/i386.md (push peephole2s): Replace
	"!ix86_using_red_zone ()" with "ix86_red_zone_size == 0".

gcc/testsuite/

	PR target/82499
	* gcc.target/i386/pr82499-1.c: New file.
	* gcc.target/i386/pr82499-2.c: Likewise.
	* gcc.target/i386/pr82499-3.c: Likewise.
---
 gcc/config/i386/i386.h                    |  1 +
 gcc/config/i386/i386.md                   |  8 ++++----
 gcc/testsuite/gcc.target/i386/pr82499-1.c | 21 +++++++++++++++++++++
 gcc/testsuite/gcc.target/i386/pr82499-2.c | 21 +++++++++++++++++++++
 gcc/testsuite/gcc.target/i386/pr82499-3.c | 21 +++++++++++++++++++++
 5 files changed, 68 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr82499-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr82499-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr82499-3.c

Comments

Uros Bizjak Oct. 13, 2017, 7:25 a.m. | #1
On Wed, Oct 11, 2017 at 3:16 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> Check red zone size, instead of if red zone is available, in push
> peephole2s.
>
> Tested on i686 and x86-64.  OK for master?

Please rename variable to ix86_red_zone_size, as Jakub suggested in the PR.

OK for mainline with this change.

Thanks,
Uros.

>
> H.J.
> ---
> gcc/
>
>         PR target/82499
>         * config/i386/i386.h (x86_red_zone_size): New.
>         * config/i386/i386.md (push peephole2s): Replace
>         "!ix86_using_red_zone ()" with "ix86_red_zone_size == 0".
>
> gcc/testsuite/
>
>         PR target/82499
>         * gcc.target/i386/pr82499-1.c: New file.
>         * gcc.target/i386/pr82499-2.c: Likewise.
>         * gcc.target/i386/pr82499-3.c: Likewise.
> ---
>  gcc/config/i386/i386.h                    |  1 +
>  gcc/config/i386/i386.md                   |  8 ++++----
>  gcc/testsuite/gcc.target/i386/pr82499-1.c | 21 +++++++++++++++++++++
>  gcc/testsuite/gcc.target/i386/pr82499-2.c | 21 +++++++++++++++++++++
>  gcc/testsuite/gcc.target/i386/pr82499-3.c | 21 +++++++++++++++++++++
>  5 files changed, 68 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr82499-1.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr82499-2.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr82499-3.c
>
> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> index ef88d89cae2..197f4e22d91 100644
> --- a/gcc/config/i386/i386.h
> +++ b/gcc/config/i386/i386.h
> @@ -2603,6 +2603,7 @@ struct GTY(()) machine_function {
>  #define ix86_current_function_calls_tls_descriptor \
>    (ix86_tls_descriptor_calls_expanded_in_cfun && df_regs_ever_live_p (SP_REG))
>  #define ix86_static_chain_on_stack (cfun->machine->static_chain_on_stack)
> +#define x86_red_zone_size (cfun->machine->frame.red_zone_size)
>
>  /* Control behavior of x86_file_start.  */
>  #define X86_FILE_START_VERSION_DIRECTIVE false
> diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
> index 1a794c0ae06..57d446857af 100644
> --- a/gcc/config/i386/i386.md
> +++ b/gcc/config/i386/i386.md
> @@ -18827,7 +18827,7 @@
>               (clobber (mem:BLK (scratch)))])]
>    "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
>     && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)
> -   && !ix86_using_red_zone ()"
> +   && x86_red_zone_size == 0"
>    [(clobber (match_dup 1))
>     (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
>               (clobber (mem:BLK (scratch)))])])
> @@ -18841,7 +18841,7 @@
>               (clobber (mem:BLK (scratch)))])]
>    "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
>     && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)
> -   && !ix86_using_red_zone ()"
> +   && x86_red_zone_size == 0"
>    [(clobber (match_dup 1))
>     (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
>     (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
> @@ -18856,7 +18856,7 @@
>               (clobber (reg:CC FLAGS_REG))])]
>    "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
>     && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)
> -   && !ix86_using_red_zone ()"
> +   && x86_red_zone_size == 0"
>    [(clobber (match_dup 1))
>     (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
>
> @@ -18868,7 +18868,7 @@
>               (clobber (reg:CC FLAGS_REG))])]
>    "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
>     && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)
> -   && !ix86_using_red_zone ()"
> +   && x86_red_zone_size == 0"
>    [(clobber (match_dup 1))
>     (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
>     (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
> diff --git a/gcc/testsuite/gcc.target/i386/pr82499-1.c b/gcc/testsuite/gcc.target/i386/pr82499-1.c
> new file mode 100644
> index 00000000000..3aba62a466f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr82499-1.c
> @@ -0,0 +1,21 @@
> +/* { dg-do compile } */
> +/* The pic register save adds unavoidable stack pointer references.  */
> +/* { dg-skip-if "" { ia32 && { ! nonpic } } } */
> +/* These options are selected to ensure 1 word needs to be allocated
> +   on the stack to maintain alignment for the call.  This should be
> +   transformed to push+pop.  We also want to force unwind info updates.  */
> +/* { dg-options "-Os -fomit-frame-pointer -fasynchronous-unwind-tables" } */
> +/* { dg-additional-options "-mpreferred-stack-boundary=3" { target ia32 } } */
> +/* { dg-additional-options "-mpreferred-stack-boundary=4" { target { ! ia32 } } } */
> +/* ms_abi has reserved stack-region.  */
> +/* { dg-skip-if "" { x86_64-*-mingw* } } */
> +
> +extern void g (void);
> +int
> +f (void)
> +{
> +  g ();
> +  return 42;
> +}
> +
> +/* { dg-final { scan-assembler-not "(sub|add)(l|q)\[\\t \]*\\$\[0-9\]*,\[\\t \]*%\[re\]?sp" } } */
> diff --git a/gcc/testsuite/gcc.target/i386/pr82499-2.c b/gcc/testsuite/gcc.target/i386/pr82499-2.c
> new file mode 100644
> index 00000000000..dde4d657e1a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr82499-2.c
> @@ -0,0 +1,21 @@
> +/* { dg-do compile } */
> +/* The pic register save adds unavoidable stack pointer references.  */
> +/* { dg-skip-if "" { ia32 && { ! nonpic } } } */
> +/* These options are selected to ensure 1 word needs to be allocated
> +   on the stack to maintain alignment for the call.  This should be
> +   transformed to push+pop.  We also want to force unwind info updates.  */
> +/* { dg-options "-Os -fomit-frame-pointer -fasynchronous-unwind-tables" } */
> +/* { dg-additional-options "-mpreferred-stack-boundary=3" { target ia32 } } */
> +/* { dg-additional-options "-mpreferred-stack-boundary=4 -mno-red-zone" { target { ! ia32 } } } */
> +/* ms_abi has reserved stack-region.  */
> +/* { dg-skip-if "" { x86_64-*-mingw* } } */
> +
> +extern void g (void);
> +int
> +f (void)
> +{
> +  g ();
> +  return 42;
> +}
> +
> +/* { dg-final { scan-assembler-not "(sub|add)(l|q)\[\\t \]*\\$\[0-9\]*,\[\\t \]*%\[re\]?sp" } } */
> diff --git a/gcc/testsuite/gcc.target/i386/pr82499-3.c b/gcc/testsuite/gcc.target/i386/pr82499-3.c
> new file mode 100644
> index 00000000000..b55a860fcca
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr82499-3.c
> @@ -0,0 +1,21 @@
> +/* { dg-do compile } */
> +/* The pic register save adds unavoidable stack pointer references.  */
> +/* { dg-skip-if "" { ia32 && { ! nonpic } } } */
> +/* These options are selected to ensure 1 word needs to be allocated
> +   on the stack to maintain alignment for the call.  This should be
> +   transformed to push+pop.  We also want to force unwind info updates.  */
> +/* { dg-options "-O2 -mtune-ctrl=single_push,single_pop -fomit-frame-pointer -fasynchronous-unwind-tables" } */
> +/* { dg-additional-options "-mpreferred-stack-boundary=3" { target ia32 } } */
> +/* { dg-additional-options "-mpreferred-stack-boundary=4" { target { ! ia32 } } } */
> +/* ms_abi has reserved stack-region.  */
> +/* { dg-skip-if "" { x86_64-*-mingw* } } */
> +
> +extern void g (void);
> +int
> +f (void)
> +{
> +  g ();
> +  return 42;
> +}
> +
> +/* { dg-final { scan-assembler-not "(sub|add)(l|q)\[\\t \]*\\$\[0-9\]*,\[\\t \]*%\[re\]?sp" } } */
> --
> 2.13.6
>

Patch

diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index ef88d89cae2..197f4e22d91 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2603,6 +2603,7 @@  struct GTY(()) machine_function {
 #define ix86_current_function_calls_tls_descriptor \
   (ix86_tls_descriptor_calls_expanded_in_cfun && df_regs_ever_live_p (SP_REG))
 #define ix86_static_chain_on_stack (cfun->machine->static_chain_on_stack)
+#define x86_red_zone_size (cfun->machine->frame.red_zone_size)
 
 /* Control behavior of x86_file_start.  */
 #define X86_FILE_START_VERSION_DIRECTIVE false
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 1a794c0ae06..57d446857af 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -18827,7 +18827,7 @@ 
 	      (clobber (mem:BLK (scratch)))])]
   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
    && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)
-   && !ix86_using_red_zone ()"
+   && x86_red_zone_size == 0"
   [(clobber (match_dup 1))
    (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
 	      (clobber (mem:BLK (scratch)))])])
@@ -18841,7 +18841,7 @@ 
 	      (clobber (mem:BLK (scratch)))])]
   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)
-   && !ix86_using_red_zone ()"
+   && x86_red_zone_size == 0"
   [(clobber (match_dup 1))
    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
    (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
@@ -18856,7 +18856,7 @@ 
 	      (clobber (reg:CC FLAGS_REG))])]
   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
    && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)
-   && !ix86_using_red_zone ()"
+   && x86_red_zone_size == 0"
   [(clobber (match_dup 1))
    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
 
@@ -18868,7 +18868,7 @@ 
 	      (clobber (reg:CC FLAGS_REG))])]
   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)
-   && !ix86_using_red_zone ()"
+   && x86_red_zone_size == 0"
   [(clobber (match_dup 1))
    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
diff --git a/gcc/testsuite/gcc.target/i386/pr82499-1.c b/gcc/testsuite/gcc.target/i386/pr82499-1.c
new file mode 100644
index 00000000000..3aba62a466f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr82499-1.c
@@ -0,0 +1,21 @@ 
+/* { dg-do compile } */
+/* The pic register save adds unavoidable stack pointer references.  */
+/* { dg-skip-if "" { ia32 && { ! nonpic } } } */
+/* These options are selected to ensure 1 word needs to be allocated
+   on the stack to maintain alignment for the call.  This should be
+   transformed to push+pop.  We also want to force unwind info updates.  */
+/* { dg-options "-Os -fomit-frame-pointer -fasynchronous-unwind-tables" } */
+/* { dg-additional-options "-mpreferred-stack-boundary=3" { target ia32 } } */
+/* { dg-additional-options "-mpreferred-stack-boundary=4" { target { ! ia32 } } } */
+/* ms_abi has reserved stack-region.  */
+/* { dg-skip-if "" { x86_64-*-mingw* } } */
+
+extern void g (void);
+int
+f (void)
+{
+  g ();
+  return 42;
+}
+
+/* { dg-final { scan-assembler-not "(sub|add)(l|q)\[\\t \]*\\$\[0-9\]*,\[\\t \]*%\[re\]?sp" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr82499-2.c b/gcc/testsuite/gcc.target/i386/pr82499-2.c
new file mode 100644
index 00000000000..dde4d657e1a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr82499-2.c
@@ -0,0 +1,21 @@ 
+/* { dg-do compile } */
+/* The pic register save adds unavoidable stack pointer references.  */
+/* { dg-skip-if "" { ia32 && { ! nonpic } } } */
+/* These options are selected to ensure 1 word needs to be allocated
+   on the stack to maintain alignment for the call.  This should be
+   transformed to push+pop.  We also want to force unwind info updates.  */
+/* { dg-options "-Os -fomit-frame-pointer -fasynchronous-unwind-tables" } */
+/* { dg-additional-options "-mpreferred-stack-boundary=3" { target ia32 } } */
+/* { dg-additional-options "-mpreferred-stack-boundary=4 -mno-red-zone" { target { ! ia32 } } } */
+/* ms_abi has reserved stack-region.  */
+/* { dg-skip-if "" { x86_64-*-mingw* } } */
+
+extern void g (void);
+int
+f (void)
+{
+  g ();
+  return 42;
+}
+
+/* { dg-final { scan-assembler-not "(sub|add)(l|q)\[\\t \]*\\$\[0-9\]*,\[\\t \]*%\[re\]?sp" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr82499-3.c b/gcc/testsuite/gcc.target/i386/pr82499-3.c
new file mode 100644
index 00000000000..b55a860fcca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr82499-3.c
@@ -0,0 +1,21 @@ 
+/* { dg-do compile } */
+/* The pic register save adds unavoidable stack pointer references.  */
+/* { dg-skip-if "" { ia32 && { ! nonpic } } } */
+/* These options are selected to ensure 1 word needs to be allocated
+   on the stack to maintain alignment for the call.  This should be
+   transformed to push+pop.  We also want to force unwind info updates.  */
+/* { dg-options "-O2 -mtune-ctrl=single_push,single_pop -fomit-frame-pointer -fasynchronous-unwind-tables" } */
+/* { dg-additional-options "-mpreferred-stack-boundary=3" { target ia32 } } */
+/* { dg-additional-options "-mpreferred-stack-boundary=4" { target { ! ia32 } } } */
+/* ms_abi has reserved stack-region.  */
+/* { dg-skip-if "" { x86_64-*-mingw* } } */
+
+extern void g (void);
+int
+f (void)
+{
+  g ();
+  return 42;
+}
+
+/* { dg-final { scan-assembler-not "(sub|add)(l|q)\[\\t \]*\\$\[0-9\]*,\[\\t \]*%\[re\]?sp" } } */