From 69bd5d473d22157d0737fc20e98eb3347cbd6ab5 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 15 Dec 2020 10:16:08 +0100 Subject: [PATCH] i386: Fix up -march=x86-64-v[234] vs. target attribute [PR98274] 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". 2020-12-15 Jakub Jelinek 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. --- gcc/config/i386/i386-options.c | 14 +++++++------- gcc/testsuite/gcc.target/i386/pr98274.c | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr98274.c diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c index 86bbb24606d..2999b611273 100644 --- a/gcc/config/i386/i386-options.c +++ b/gcc/config/i386/i386-options.c @@ -1884,9 +1884,7 @@ ix86_option_override_internal (bool main_args_p, 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_args_p, /* 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 diff --git a/gcc/testsuite/gcc.target/i386/pr98274.c b/gcc/testsuite/gcc.target/i386/pr98274.c new file mode 100644 index 00000000000..dd08f33cf53 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98274.c @@ -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) +{ +} -- 2.30.2