public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hongyu Wang <hongyu.wang@intel.com>
To: gcc-patches@gcc.gnu.org
Cc: ubizjak@gmail.com, hongtao.liu@intel.com
Subject: [PATCH] i386: Relax inline requirement for functions with different target attrs
Date: Mon, 26 Jun 2023 10:34:08 +0800	[thread overview]
Message-ID: <20230626023408.33758-1-hongyu.wang@intel.com> (raw)

Hi,

For function with different target attributes, current logic rejects to
inline the callee when any arch or tune is mismatched. Relax the
condition to honor just prefer_vecotr_width_type and other flags that
may cause safety issue so caller can get more optimization opportunity.

Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,}

Ok for trunk?

gcc/ChangeLog:

	* config/i386/i386.cc (ix86_can_inline_p): Do not check arch or
	tune directly, just check prefer_vector_width_type and make sure
	not to inline if they mismatch.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/inline-target-attr.c: New test.
---
 gcc/config/i386/i386.cc                       | 11 +++++----
 .../gcc.target/i386/inline-target-attr.c      | 24 +++++++++++++++++++
 2 files changed, 30 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/inline-target-attr.c

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 0761965344b..1d86384ac06 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -605,11 +605,12 @@ ix86_can_inline_p (tree caller, tree callee)
 	       != (callee_opts->x_target_flags & ~always_inline_safe_mask))
     ret = false;
 
-  /* See if arch, tune, etc. are the same.  */
-  else if (caller_opts->arch != callee_opts->arch)
-    ret = false;
-
-  else if (!always_inline && caller_opts->tune != callee_opts->tune)
+  /* Do not inline when specified perfer-vector-width mismatched between
+     callee and caller.  */
+  else if ((callee_opts->x_prefer_vector_width_type != PVW_NONE
+	   && caller_opts->x_prefer_vector_width_type != PVW_NONE)
+	   && callee_opts->x_prefer_vector_width_type
+	      != caller_opts->x_prefer_vector_width_type)
     ret = false;
 
   else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath
diff --git a/gcc/testsuite/gcc.target/i386/inline-target-attr.c b/gcc/testsuite/gcc.target/i386/inline-target-attr.c
new file mode 100644
index 00000000000..995502165f0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/inline-target-attr.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler-not "call\[ \t\]callee" } } */
+
+__attribute__((target("arch=skylake")))
+int callee (int n)
+{
+  int sum = 0;
+  for (int i = 0; i < n; i++)
+    {
+      if (i % 2 == 0)
+	sum +=i;
+      else
+	sum += (i - 1);
+    }
+  return sum + n;
+}
+
+__attribute__((target("arch=icelake-server")))
+int caller (int n)
+{
+  return callee (n) + n;
+}
+
-- 
2.31.1


             reply	other threads:[~2023-06-26  2:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-26  2:34 Hongyu Wang [this message]
2023-06-27  9:16 ` Uros Bizjak
2023-06-28  1:49   ` Hongyu Wang
2023-06-28  6:42     ` Uros Bizjak
2023-06-28  8:13       ` Hongyu Wang
2023-06-28  8:39         ` Uros Bizjak

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=20230626023408.33758-1-hongyu.wang@intel.com \
    --to=hongyu.wang@intel.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hongtao.liu@intel.com \
    --cc=ubizjak@gmail.com \
    /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).