public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-5441] i386: Fix up handling of target attribute [PR101180]
Date: Sun, 21 Nov 2021 20:07:03 +0000 (GMT)	[thread overview]
Message-ID: <20211121200703.4DD343858C3A@sourceware.org> (raw)

https://gcc.gnu.org/g:364539710f828851b9fac51c39033cd09aa620de

commit r12-5441-g364539710f828851b9fac51c39033cd09aa620de
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sun Nov 21 21:06:23 2021 +0100

    i386: Fix up handling of target attribute [PR101180]
    
    As shown in the testcase below, if a function has multiple target attributes
    (rather than a single one with one or more arguments) or if a function
    gets one target attribute on one declaration and another one on another
    declaration, on x86 their effect is not combined into
    DECL_FUNCTION_SPECIFIC_TARGET, but instead only the last processed target
    attribute wins.  aarch64 handles this right, the following patch follows
    what it does, i.e. only start with target_option_default_node if
    DECL_FUNCTION_SPECIFIC_TARGET is previously NULL (i.e. the first target
    attribute being processed on a function) and otherwise start from the
    previous DECL_FUNCTION_SPECIFIC_TARGET.
    
    2021-11-21  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/101180
            * config/i386/i386-options.c (ix86_valid_target_attribute_p): If
            fndecl already has DECL_FUNCTION_SPECIFIC_TARGET, use that as base
            instead of target_option_default_node.
    
            * gcc.target/i386/pr101180.c: New test.

Diff:
---
 gcc/config/i386/i386-options.c           |  5 ++++-
 gcc/testsuite/gcc.target/i386/pr101180.c | 12 ++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index feff2584f41..a4da8331b8b 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -1443,8 +1443,11 @@ ix86_valid_target_attribute_p (tree fndecl,
 
   /* Initialize func_options to the default before its target options can
      be set.  */
+  tree old_target = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
+  if (old_target == NULL_TREE)
+    old_target = target_option_default_node;
   cl_target_option_restore (&func_options, &func_options_set,
-			    TREE_TARGET_OPTION (target_option_default_node));
+			    TREE_TARGET_OPTION (old_target));
 
   /* FLAGS == 1 is used for target_clones attribute.  */
   new_target
diff --git a/gcc/testsuite/gcc.target/i386/pr101180.c b/gcc/testsuite/gcc.target/i386/pr101180.c
new file mode 100644
index 00000000000..1ac4cb5e2b5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr101180.c
@@ -0,0 +1,12 @@
+/* PR c++/101180 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mno-avx -mno-crc32" } */
+
+#include <x86intrin.h>
+
+__attribute__((target ("avx"))) __attribute__((target ("crc32"))) void
+foo (__m256 *p, unsigned int *q)
+{
+  __m256 c = _mm256_and_ps (p[0], p[1]);
+  *q = __crc32b (*q, 0x55);
+}


                 reply	other threads:[~2021-11-21 20:07 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=20211121200703.4DD343858C3A@sourceware.org \
    --to=jakub@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).