public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH] ipa: propagate attributes for target attribute clones
Date: Mon, 3 Apr 2023 11:02:28 +0200	[thread overview]
Message-ID: <200bdb15-2621-2ba3-fc04-5fd20821f871@suse.cz> (raw)

Hi.

The patch propagates noreturn attribute for MV functions. However, I noticed
we've got the following ICE when we do the same for TREE_READONLY attr:

$ cat tc.c
double bar() __attribute__((target_clones("avx,avx2,avx512f,default")));
double bar() { return 1.2f; }

int foo() { return (int)bar(); }

$ ./xgcc -B. ~/Programming/testcases/tc.c -O3 -c -fprofile-generate
/home/marxin/Programming/testcases/tc.c: In function ‘foo’:
/home/marxin/Programming/testcases/tc.c:4:5: error: virtual definition of statement not up to date
     4 | int foo() { return (int)bar(); }
       |     ^~~
_1 = bar ();
during GIMPLE pass: fixup_cfg

Thus my ambition is to propagate only noreturn attr.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR ipa/106816

gcc/ChangeLog:

	* config/i386/i386-features.cc (ix86_get_function_versions_dispatcher):
	Propagate function attributes for clones.

gcc/testsuite/ChangeLog:

	* g++.target/i386/pr106816.C: New test.

Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
---
  gcc/config/i386/i386-features.cc         |  1 +
  gcc/testsuite/g++.target/i386/pr106816.C | 23 +++++++++++++++++++++++
  2 files changed, 24 insertions(+)
  create mode 100644 gcc/testsuite/g++.target/i386/pr106816.C

diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
index c09abf8fc20..f2b0d59a73c 100644
--- a/gcc/config/i386/i386-features.cc
+++ b/gcc/config/i386/i386-features.cc
@@ -3379,6 +3379,7 @@ ix86_get_function_versions_dispatcher (void *decl)
        /* Right now, the dispatching is done via ifunc.  */
        dispatch_decl = make_dispatcher_decl (default_node->decl);
        TREE_NOTHROW (dispatch_decl) = TREE_NOTHROW (fn);
+      TREE_THIS_VOLATILE (dispatch_decl) = TREE_THIS_VOLATILE (fn);
  
        dispatcher_node = cgraph_node::get_create (dispatch_decl);
        gcc_assert (dispatcher_node != NULL);
diff --git a/gcc/testsuite/g++.target/i386/pr106816.C b/gcc/testsuite/g++.target/i386/pr106816.C
new file mode 100644
index 00000000000..0f5cc1f13dd
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr106816.C
@@ -0,0 +1,23 @@
+// PR ipa/106816
+
+// { dg-do compile }
+// { dg-require-ifunc "" }
+// { dg-options "-O2 -fdump-tree-optimized" }
+
+__attribute__((noreturn, target("default"))) void f()
+{
+  for (;;) {}
+}
+
+__attribute__((noreturn, target("sse4.2,bmi"))) void f()
+{
+  for (;;) {}
+}
+
+int main()
+{
+  f();
+  return 12345;
+}
+
+/* { dg-final { scan-tree-dump-not "12345" "optimized" } } */
-- 
2.40.0


             reply	other threads:[~2023-04-03  9:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-03  9:02 Martin Liška [this message]
2023-04-11  8:30 ` Richard Biener

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=200bdb15-2621-2ba3-fc04-5fd20821f871@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@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).