diff mbox series

x86-64: Use push2/pop2 only if the incoming stack is 16-byte aligned

Message ID 20240213195800.4145414-1-hjl.tools@gmail.com
State New
Headers show
Series x86-64: Use push2/pop2 only if the incoming stack is 16-byte aligned | expand

Commit Message

H.J. Lu Feb. 13, 2024, 7:58 p.m. UTC
Since push2/pop2 requires 16-byte stack alignment, don't use them if the
incoming stack isn't 16-byte aligned.

gcc/

	PR target/113876
	* config/i386/i386.cc (ix86_pro_and_epilogue_can_use_push2pop2):
	Return false if the incoming stack isn't 16-byte aligned.

gcc/testsuite/

	PR target/113876
	* gcc.target/i386/pr113876.c: New test.
---
 gcc/config/i386/i386.cc                  |  6 ++++++
 gcc/testsuite/gcc.target/i386/pr113876.c | 10 ++++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr113876.c

Comments

Jakub Jelinek Feb. 13, 2024, 8:01 p.m. UTC | #1
On Tue, Feb 13, 2024 at 11:58:00AM -0800, H.J. Lu wrote:
> Since push2/pop2 requires 16-byte stack alignment, don't use them if the
> incoming stack isn't 16-byte aligned.
> 
> gcc/
> 
> 	PR target/113876
> 	* config/i386/i386.cc (ix86_pro_and_epilogue_can_use_push2pop2):
> 	Return false if the incoming stack isn't 16-byte aligned.
> 
> gcc/testsuite/
> 
> 	PR target/113876
> 	* gcc.target/i386/pr113876.c: New test.

LGTM.

	Jakub
diff mbox series

Patch

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index dbb26e8f76a..a4e12602f70 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -6807,6 +6807,12 @@  get_probe_interval (void)
 static bool
 ix86_pro_and_epilogue_can_use_push2pop2 (int nregs)
 {
+  /* Use push2/pop2 only if the incoming stack is 16-byte aligned.  */
+  unsigned int incoming_stack_boundary
+    = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
+       ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
+  if (incoming_stack_boundary % 128 != 0)
+    return false;
   int aligned = cfun->machine->fs.sp_offset % 16 == 0;
   return TARGET_APX_PUSH2POP2
 	 && !cfun->machine->frame.save_regs_using_mov
diff --git a/gcc/testsuite/gcc.target/i386/pr113876.c b/gcc/testsuite/gcc.target/i386/pr113876.c
new file mode 100644
index 00000000000..fbf26f6ab8f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr113876.c
@@ -0,0 +1,10 @@ 
+/* { dg-do compile { target { lp64 } } } */
+/* { dg-options "-O -mapxf -mpreferred-stack-boundary=3 -finstrument-functions -mcmodel=large" } */
+
+void
+bar (unsigned long *p)
+{
+  p[0] = 0;
+  p[1] = 0;
+  p[2] = 0;
+}