public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] ipa: propagate attributes for target attribute clones
@ 2023-04-03  9:02 Martin Liška
  2023-04-11  8:30 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2023-04-03  9:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: H.J. Lu

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ipa: propagate attributes for target attribute clones
  2023-04-03  9:02 [PATCH] ipa: propagate attributes for target attribute clones Martin Liška
@ 2023-04-11  8:30 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-04-11  8:30 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches, H.J. Lu

On Mon, Apr 3, 2023 at 11:03 AM Martin Liška <mliska@suse.cz> wrote:
>
> 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.

But wouldn't that mean the IL needs fixup for the call to the dispatcher
which would be non-const for actually const implementations?  That said,
maybe the IPA cloning for the actual functions need adjustments as well?

> 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
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-11  8:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-03  9:02 [PATCH] ipa: propagate attributes for target attribute clones Martin Liška
2023-04-11  8:30 ` Richard Biener

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).