public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: H.J. Lu <hjl@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8966] x86-64: Use push2/pop2 only if the incoming stack is 16-byte aligned
Date: Tue, 13 Feb 2024 20:05:22 +0000 (GMT)	[thread overview]
Message-ID: <20240213200523.6E40C3857C5B@sourceware.org> (raw)

https://gcc.gnu.org/g:ab71fd7ac7a2307723117c796e7ae4d7e9711058

commit r14-8966-gab71fd7ac7a2307723117c796e7ae4d7e9711058
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Feb 13 11:58:00 2024 -0800

    x86-64: Use push2/pop2 only if the incoming stack is 16-byte aligned
    
    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.

Diff:
---
 gcc/config/i386/i386.cc                  |  6 ++++++
 gcc/testsuite/gcc.target/i386/pr113876.c | 10 ++++++++++
 2 files changed, 16 insertions(+)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index dbb26e8f76ab..a4e12602f704 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 000000000000..fbf26f6ab8f2
--- /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;
+}

                 reply	other threads:[~2024-02-13 20:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240213200523.6E40C3857C5B@sourceware.org \
    --to=hjl@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).