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>
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);
--- /dev/null
+/* { 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" } } */