[PATCH] i386: Fix up handling of target attribute [PR101180]

Uros Bizjak ubizjak@gmail.com
Sun Nov 21 20:02:40 GMT 2021


On Sat, Nov 20, 2021 at 9:20 AM Jakub Jelinek <jakub@redhat.com> wrote:
>
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2021-11-20  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.

OK.

Thanks,
Uros.

>
> --- gcc/config/i386/i386-options.c.jj   2021-11-19 12:48:56.507415161 +0100
> +++ gcc/config/i386/i386-options.c      2021-11-19 13:04:31.618044781 +0100
> @@ -1443,8 +1443,11 @@ ix86_valid_target_attribute_p (tree fnde
>
>    /* 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
> --- gcc/testsuite/gcc.target/i386/pr101180.c.jj 2021-11-19 13:24:19.334132937 +0100
> +++ gcc/testsuite/gcc.target/i386/pr101180.c    2021-11-19 13:23:56.676454806 +0100
> @@ -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);
> +}
>
>         Jakub
>


More information about the Gcc-patches mailing list