__attribute__ ((target("arch=broadwell"))) should enable AVX with -mavx
at command-line. When we apply target attribute, we need to clear
x_ix86_isa_flags_explicit and x_ix86_isa_flags2_explicit, which are
turned on at command-line, so that target features will be enabled.
mv17.C has a version for Haswell. On machines with Haswell ISAs, when
GCC is configured with --with-arch=native, all versions will be compiled
with Haswell ISAs. Compile mv17.C with -march=x86-64 to force that only
Haswell version is compiled with -march=haswell.
gcc/
PR target/89456
* config/i386/i386.c (ix86_valid_target_attribute_tree): Allow
enabling ISAs which have been enabled at command-line.
gcc/testsuite/
PR target/89456
* g++.target/i386/mv17.C: Add -march=x86-64.
* gcc.target/i386/pr89456-1.c: New test.
---
gcc/config/i386/i386.c | 6 ++++++
gcc/testsuite/g++.target/i386/mv17.C | 2 +-
gcc/testsuite/gcc.target/i386/pr89456-1.c | 9 +++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr89456-1.c
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index c8f9957163b..2b72ca8359f 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -5539,6 +5539,12 @@ ix86_valid_target_attribute_tree (tree args,
= TREE_TARGET_OPTION (target_option_default_node);
struct gcc_options enum_opts_set;
+ /* Allow enabling ISAs which have been enabled at command-line so
+ that __attribute__ ((target("arch=broadwell"))) enables AVX when
+ there is -mavx at command-line. */
+ opts->x_ix86_isa_flags_explicit &= ~ix86_isa_flags;
+ opts->x_ix86_isa_flags2_explicit &= ~ix86_isa_flags2;
+
memset (&enum_opts_set, 0, sizeof (enum_opts_set));
/* Process each of the options on the chain. */
diff --git a/gcc/testsuite/g++.target/i386/mv17.C
b/gcc/testsuite/g++.target/i386/mv17.C
index fefbfaac6ff..17d125227d7 100644
--- a/gcc/testsuite/g++.target/i386/mv17.C
+++ b/gcc/testsuite/g++.target/i386/mv17.C
@@ -2,7 +2,7 @@
// { dg-do run }
// { dg-require-ifunc "" }
-// { dg-options "-O2" }
+// { dg-options "-O2 -march=x86-64" }
#include <assert.h>
diff --git a/gcc/testsuite/gcc.target/i386/pr89456-1.c
b/gcc/testsuite/gcc.target/i386/pr89456-1.c
new file mode 100644
index 00000000000..87a3a820898
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr89456-1.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx -march=x86-64" } */
+
+__attribute__ ((target("arch=broadwell")))
+float
+foo (float x)
+{
+ return x;
+}
--
2.20.1