]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Sync tune_string with arch_string for target attribute arch=*
authorHongyu Wang <hongyu.wang@intel.com>
Sun, 25 Jun 2023 01:50:21 +0000 (09:50 +0800)
committerHongyu Wang <hongyu.wang@intel.com>
Thu, 29 Jun 2023 00:26:23 +0000 (08:26 +0800)
For function with target attribute arch=*, current logic will set its
tune to -mtune from command line so all target_clones will get same
tuning flags which would affect the performance for each clone. Override
tune with arch if tune was not explicitly specified to get proper tuning
flags for target_clones.

gcc/ChangeLog:

* config/i386/i386-options.cc (ix86_valid_target_attribute_tree):
Override tune_string with arch_string if tune_string is not
explicitly specified.

gcc/testsuite/ChangeLog:

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

(cherry picked from commit 2916278d14e9ac28c361c396a67256acbebda6e8)

gcc/config/i386/i386-options.cc
gcc/testsuite/gcc.target/i386/mvc17.c [new file with mode: 0644]

index 70ddcd284c4b6b1310fcd69548b0dca237ec35a4..27d16986a2fa9a85dd5fd7f269d5723dc4209a6c 100644 (file)
@@ -1378,7 +1378,11 @@ ix86_valid_target_attribute_tree (tree fndecl, tree args,
       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
        opts->x_ix86_tune_string
          = ggc_strdup (option_strings[IX86_FUNCTION_SPECIFIC_TUNE]);
-      else if (orig_tune_defaulted)
+      /* If we have explicit arch string and no tune string specified, set
+        tune_string to NULL and later it will be overriden by arch_string
+        so target clones can get proper optimization.  */
+      else if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
+              || orig_tune_defaulted)
        opts->x_ix86_tune_string = NULL;
 
       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
diff --git a/gcc/testsuite/gcc.target/i386/mvc17.c b/gcc/testsuite/gcc.target/i386/mvc17.c
new file mode 100644 (file)
index 0000000..8b83c1a
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+/* { dg-options "-O2 -march=x86-64" } */
+/* { dg-final { scan-assembler-times "rep mov" 1 } } */
+
+__attribute__((target_clones("default","arch=icelake-server")))
+void
+foo (char *a, char *b, int size)
+{
+  __builtin_memcpy (a, b, size & 0x7F);
+}