diff mbox series

i386: Fix up -march=x86-64-v[234] vs. target attribute [PR98274]

Message ID 20201215090255.GK3788@tucnak
State New
Headers show
Series i386: Fix up -march=x86-64-v[234] vs. target attribute [PR98274] | expand

Commit Message

Jakub Jelinek Dec. 15, 2020, 9:02 a.m. UTC
Hi!

The following testcase fails to compile.  The problem is that
when ix86_option_override_internal is called the first time for command
line, it sees -mtune= wasn't present on the command line and so as fallback
sets ix86_tune_string to ix86_arch_string value ("x86-64-v2"), but
ix86_tune_specified is false, so we don't find the tuning in the table
but don't error on it.
When processing the target attribute, ix86_tune_string is what
it was earlier left with, but this time ix86_tune_specified is true and
so we error on it.

The following patch does what is done already e.g. for "x86-64" march,
in particular default the tuning to "generic".

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-12-15  Jakub Jelinek  <jakub@redhat.com>

	PR target/98274
	* config/i386/i386-options.c (ix86_option_override_internal): Set
	ix86_tune_string to "generic" even when it wasn't specified and
	ix86_arch_string is "x86-64-v2", "x86-64-v3" or "x86-64-v4".
	Remove useless {}s around a single statement.

	* gcc.target/i386/pr98274.c: New test.


	Jakub

Comments

Uros Bizjak Dec. 15, 2020, 9:09 a.m. UTC | #1
On Tue, Dec 15, 2020 at 10:03 AM Jakub Jelinek <jakub@redhat.com> wrote:
>
> Hi!
>
> The following testcase fails to compile.  The problem is that
> when ix86_option_override_internal is called the first time for command
> line, it sees -mtune= wasn't present on the command line and so as fallback
> sets ix86_tune_string to ix86_arch_string value ("x86-64-v2"), but
> ix86_tune_specified is false, so we don't find the tuning in the table
> but don't error on it.
> When processing the target attribute, ix86_tune_string is what
> it was earlier left with, but this time ix86_tune_specified is true and
> so we error on it.
>
> The following patch does what is done already e.g. for "x86-64" march,
> in particular default the tuning to "generic".
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2020-12-15  Jakub Jelinek  <jakub@redhat.com>
>
>         PR target/98274
>         * config/i386/i386-options.c (ix86_option_override_internal): Set
>         ix86_tune_string to "generic" even when it wasn't specified and
>         ix86_arch_string is "x86-64-v2", "x86-64-v3" or "x86-64-v4".
>         Remove useless {}s around a single statement.
>
>         * gcc.target/i386/pr98274.c: New test.

OK.

Thanks,
Uros.

> --- gcc/config/i386/i386-options.c.jj   2020-12-14 13:31:51.864733294 +0100
> +++ gcc/config/i386/i386-options.c      2020-12-14 14:40:09.795222723 +0100
> @@ -1884,9 +1884,7 @@ ix86_option_override_internal (bool main
>              as -mtune=generic.  With native compilers we won't see the
>              -mtune=native, as it was changed by the driver.  */
>        if (!strcmp (opts->x_ix86_tune_string, "native"))
> -       {
> -         opts->x_ix86_tune_string = "generic";
> -       }
> +       opts->x_ix86_tune_string = "generic";
>        else if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
>          warning (OPT_Wdeprecated,
>                  main_args_p
> @@ -1908,10 +1906,12 @@ ix86_option_override_internal (bool main
>
>        /* opts->x_ix86_tune_string is set to opts->x_ix86_arch_string
>          or defaulted.  We need to use a sensible tune option.  */
> -      if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
> -       {
> -         opts->x_ix86_tune_string = "generic";
> -       }
> +      if (!strncmp (opts->x_ix86_tune_string, "x86-64", 6)
> +         && (opts->x_ix86_tune_string[6] == '\0'
> +             || (!strcmp (opts->x_ix86_tune_string + 6, "-v2")
> +                 || !strcmp (opts->x_ix86_tune_string + 6, "-v3")
> +                 || !strcmp (opts->x_ix86_tune_string + 6, "-v4"))))
> +       opts->x_ix86_tune_string = "generic";
>      }
>
>    if (opts->x_ix86_stringop_alg == rep_prefix_8_byte
> --- gcc/testsuite/gcc.target/i386/pr98274.c.jj  2020-12-14 14:44:09.197559567 +0100
> +++ gcc/testsuite/gcc.target/i386/pr98274.c     2020-12-14 14:43:22.406080077 +0100
> @@ -0,0 +1,8 @@
> +/* PR target/98274 */
> +/* { dg-do compile { target lp64 } } */
> +/* { dg-options "-mabi=sysv -O2 -march=x86-64-v2" } */
> +
> +void __attribute__((target ("avx")))
> +foo (void)
> +{
> +}
>
>         Jakub
>
diff mbox series

Patch

--- gcc/config/i386/i386-options.c.jj	2020-12-14 13:31:51.864733294 +0100
+++ gcc/config/i386/i386-options.c	2020-12-14 14:40:09.795222723 +0100
@@ -1884,9 +1884,7 @@  ix86_option_override_internal (bool main
 	     as -mtune=generic.  With native compilers we won't see the
 	     -mtune=native, as it was changed by the driver.  */
       if (!strcmp (opts->x_ix86_tune_string, "native"))
-	{
-	  opts->x_ix86_tune_string = "generic";
-	}
+	opts->x_ix86_tune_string = "generic";
       else if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
         warning (OPT_Wdeprecated,
 		 main_args_p
@@ -1908,10 +1906,12 @@  ix86_option_override_internal (bool main
 
       /* opts->x_ix86_tune_string is set to opts->x_ix86_arch_string
 	 or defaulted.  We need to use a sensible tune option.  */
-      if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
-	{
-	  opts->x_ix86_tune_string = "generic";
-	}
+      if (!strncmp (opts->x_ix86_tune_string, "x86-64", 6)
+	  && (opts->x_ix86_tune_string[6] == '\0'
+	      || (!strcmp (opts->x_ix86_tune_string + 6, "-v2")
+		  || !strcmp (opts->x_ix86_tune_string + 6, "-v3")
+		  || !strcmp (opts->x_ix86_tune_string + 6, "-v4"))))
+	opts->x_ix86_tune_string = "generic";
     }
 
   if (opts->x_ix86_stringop_alg == rep_prefix_8_byte
--- gcc/testsuite/gcc.target/i386/pr98274.c.jj	2020-12-14 14:44:09.197559567 +0100
+++ gcc/testsuite/gcc.target/i386/pr98274.c	2020-12-14 14:43:22.406080077 +0100
@@ -0,0 +1,8 @@ 
+/* PR target/98274 */
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-mabi=sysv -O2 -march=x86-64-v2" } */
+
+void __attribute__((target ("avx")))
+foo (void)
+{
+}