public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/101180] [12 Regression] Rejected code since r12-299-ga0fdff3cf33f7284
Date: Thu, 18 Nov 2021 18:01:22 +0000	[thread overview]
Message-ID: <bug-101180-4-Sb85oyp8UH@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101180-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101180

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think when instantiating templates we shouldn't be adding attributes from
current_optimize_pragma, optimization_current_node or current_target_pragma.
It shouldn't really matter where we instantiate the code from, but where it is
declared.
E.g. given
#pragma GCC push_options
#pragma GCC target "avx"
template <int N>
inline void foo ()
{
}
#pragma GCC pop_options
#pragma GCC push_options
#pragma GCC target "avx2"
void
bar ()
{
  foo<0> ();
}
#pragma GCC pop_options
both GCC 10 and 11 emit:
__attribute__((target ("avx2")))
void bar ()
{
  foo<0> ();
}


__attribute__((target ("avx")))
void foo<0> ()
{
  GIMPLE_NOP
}
but GCC 12 emits:
__attribute__((target ("avx2")))
void bar ()
{
  foo<0> ();
}


__attribute__((target ("avx2"), target ("avx")))
void foo<0> ()
{
  GIMPLE_NOP
}

Another thing is if optimize/target attributes can be ever dependent.  If they
can, I think we have another problem because clearly
ix86_valid_target_attribute_p starts from TREE_TARGET_OPTION
(target_option_default_node) rather than from DECL_FUNCTION_SPECIFIC_TARGET
(fndecl).  I think it should start from the latter if fndecl and
DECL_FUNCTION_SPECIFIC_TARGET is non-NULL (similarly for other targets),
otherwise I really don't understand how
#include <x86intrin.h>

__attribute__((target ("avx"))) __attribute__((target ("crc32"))) void
foo ()
{
  __m256 a = {}, b = {};
  __m256 c = _mm256_and_ps (a, b);
  unsigned int d = 1;
  d = __crc32b (d, 0x55);
}
can work properly (it doesn't).

For the former issue, perhaps apply_late_template_attributes could temporarily
override current_optimize_pragma, optimization_current_node and
current_target_pragma around the cplus_decl_attributes call in there.
Also scope_chain->omp_declare_target_attribute.

Note, I think older GCCs suffered from this bug too, but before
r12-299-ga0fdff3cf33f7284 we didn't call cplus_decl_attributes at least when
there wasn't any dependent attribute.  But I guess it should be easy to add
some unrelated dependent attribute to trigger it before.

  parent reply	other threads:[~2021-11-18 18:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23 13:05 [Bug c++/101180] New: " marxin at gcc dot gnu.org
2021-06-23 13:05 ` [Bug c++/101180] " marxin at gcc dot gnu.org
2021-11-18 18:01 ` jakub at gcc dot gnu.org [this message]
2021-11-18 18:26 ` jakub at gcc dot gnu.org
2021-11-19 21:10 ` cvs-commit at gcc dot gnu.org
2021-11-21 20:07 ` cvs-commit at gcc dot gnu.org
2021-11-22  9:58 ` jakub at gcc dot gnu.org
2021-11-25  7:42 ` cvs-commit at gcc dot gnu.org

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=bug-101180-4-Sb85oyp8UH@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).