]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Fix fmv priority ordering [PR target/122190]
authorAlfie Richards <alfie.richards@arm.com>
Tue, 7 Oct 2025 12:04:14 +0000 (12:04 +0000)
committerAlfie Richards <alfie.richards@arm.com>
Thu, 23 Oct 2025 12:30:31 +0000 (12:30 +0000)
This fixes the versioning rules for aarch64.

Previously this would prioritize the version string with more extensions
specified regardless of the extension.

The ACLE rules are that any two version strings should be ordered by the
highest priority feature that the versions don't have in common.

PR target/122190

gcc/ChangeLog:

* config/aarch64/aarch64.cc (compare_feature_masks): Fix version rules.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/pr122190.c: New test

Reviewed-by: Wilco Dijkstra <wilco.dijkstra@arm.com>
gcc/config/aarch64/aarch64.cc
gcc/testsuite/gcc.target/aarch64/pr122190.c [new file with mode: 0644]

index bb3a10bb610f530b97327240db82abda515293f0..a0da08e3bd53c97e85444495e2712d7a5add8cb9 100644 (file)
@@ -20607,14 +20607,8 @@ static int
 compare_feature_masks (aarch64_fmv_feature_mask mask1,
                       aarch64_fmv_feature_mask mask2)
 {
-  int pop1 = popcount_hwi (mask1);
-  int pop2 = popcount_hwi (mask2);
-  if (pop1 > pop2)
-    return 1;
-  if (pop2 > pop1)
-    return -1;
-
   auto diff_mask = mask1 ^ mask2;
+  /* If there is no difference.  */
   if (diff_mask == 0ULL)
     return 0;
   int num_features = ARRAY_SIZE (aarch64_fmv_feature_data);
diff --git a/gcc/testsuite/gcc.target/aarch64/pr122190.c b/gcc/testsuite/gcc.target/aarch64/pr122190.c
new file mode 100644 (file)
index 0000000..8546e12
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile }  */
+/* { dg-require-ifunc "" } */
+/* { dg-options "-O0 -march=armv8-a -fdump-ipa-targetclone1-details" } */
+
+int fn (int a) {return 1;}
+int fn[[gnu::target_version("sve")]] (int a) {return 2;}
+int fn[[gnu::target_version("simd+dotprod")]] (int a) {return 3;}
+int fn[[gnu::target_version("sve+fp")]] (int a) {return 2;}
+
+/* { dg-final { scan-ipa-dump-times "Version order for fn/\[0-9\]+:\\nfn\.default/\[0-9\]+\\nfn\._MsimdMdotprod/\[0-9\]+\\nfn\._Msve/\[0-9\]+\\nfn\._MfpMsve/\[0-9\]+\\n" 1 "targetclone1" } } */