On 10/8/25 14:56, [email protected] wrote:
From: Alfie Richards <[email protected]>
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
Looks good - just looking at the number of features was completely
wrong. OK.
Cheers,
Wilco
---
gcc/config/aarch64/aarch64.cc | 8 +-------
gcc/testsuite/gcc.target/aarch64/pr122190.c | 10 ++++++++++
2 files changed, 11 insertions(+), 7 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/aarch64/pr122190.c
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index b60414fceb2..e16f0c25eb9 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -20609,14 +20609,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
index 00000000000..8546e120063
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr122190.c
@@ -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" } } */