https://github.com/mikolaj-pirog created https://github.com/llvm/llvm-project/pull/184078
As in title. This adds support for using apxf in attribute target. Individual features are not supported because they all share the same cpuid so we can't distinguish them -- now compiler emits error message instead of crashing. Patch done with usage of Claude Code. I've verified that the output makes sense From 36839a382fe5b5444ef85666d46ebb18ba7ac649 Mon Sep 17 00:00:00 2001 From: "Pirog, Mikolaj Maciej" <[email protected]> Date: Mon, 2 Mar 2026 08:15:36 +0100 Subject: [PATCH] Support apxf in function multiversioning, don't support indivudal features --- clang/lib/Basic/Targets/X86.cpp | 34 +++++++++++++++++++++------- clang/test/CodeGen/attr-target-x86.c | 10 ++++++++ clang/test/Sema/attr-target.c | 21 +++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index 6f88a428b1230..f0c31dddbc205 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -179,6 +179,31 @@ bool X86TargetInfo::initFeatureMap( continue; } + // Expand apxf to the individual APX features + if (Feature == "+apxf") { + UpdatedFeaturesVec.push_back("+egpr"); + UpdatedFeaturesVec.push_back("+ndd"); + UpdatedFeaturesVec.push_back("+ccmp"); + UpdatedFeaturesVec.push_back("+nf"); + UpdatedFeaturesVec.push_back("+zu"); + if (!getTriple().isOSWindows()) { + UpdatedFeaturesVec.push_back("+push2pop2"); + UpdatedFeaturesVec.push_back("+ppx"); + } + continue; + } + + if (Feature == "-apxf") { + UpdatedFeaturesVec.push_back("-egpr"); + UpdatedFeaturesVec.push_back("-ndd"); + UpdatedFeaturesVec.push_back("-ccmp"); + UpdatedFeaturesVec.push_back("-nf"); + UpdatedFeaturesVec.push_back("-zu"); + UpdatedFeaturesVec.push_back("-push2pop2"); + UpdatedFeaturesVec.push_back("-ppx"); + continue; + } + UpdatedFeaturesVec.push_back(Feature); } @@ -1169,14 +1194,7 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) const { .Case("xsavec", true) .Case("xsaves", true) .Case("xsaveopt", true) - .Case("egpr", true) - .Case("push2pop2", true) - .Case("ppx", true) - .Case("ndd", true) - .Case("ccmp", true) - .Case("nf", true) - .Case("cf", true) - .Case("zu", true) + .Case("apxf", true) .Default(false); } diff --git a/clang/test/CodeGen/attr-target-x86.c b/clang/test/CodeGen/attr-target-x86.c index 474fa93629d89..35f07a2e0c2bb 100644 --- a/clang/test/CodeGen/attr-target-x86.c +++ b/clang/test/CodeGen/attr-target-x86.c @@ -19,6 +19,8 @@ // CHECK: define {{.*}}@f_avx10_1{{.*}} [[f_avx10_1:#[0-9]+]] // CHECK: define {{.*}}@f_prefer_256_bit({{.*}} [[f_prefer_256_bit:#[0-9]+]] // CHECK: define {{.*}}@f_no_prefer_256_bit({{.*}} [[f_no_prefer_256_bit:#[0-9]+]] +// CHECK: define {{.*}}@f_apxf({{.*}} [[f_apxf:#[0-9]+]] +// CHECK: define {{.*}}@f_no_apxf({{.*}} [[f_no_apxf:#[0-9]+]] // CHECK: [[f_default]] = {{.*}}"target-cpu"="i686" "target-features"="+cmov,+cx8,+x87" "tune-cpu"="i686" void f_default(void) {} @@ -108,3 +110,11 @@ void f_prefer_256_bit(void) {} // CHECK: [[f_no_prefer_256_bit]] = {{.*}}"target-features"="{{.*}}-prefer-256-bit __attribute__((target("no-prefer-256-bit"))) void f_no_prefer_256_bit(void) {} + +// CHECK: [[f_apxf]] = {{.*}}"target-features"="{{.*}}+ccmp{{.*}}+egpr{{.*}}+ndd{{.*}}+nf{{.*}}+ppx{{.*}}+push2pop2{{.*}}+zu +__attribute__((target("apxf"))) +void f_apxf(void) {} + +// CHECK: [[f_no_apxf]] = {{.*}}"target-features"="{{.*}}-ccmp{{.*}}-egpr{{.*}}-ndd{{.*}}-nf{{.*}}-ppx{{.*}}-push2pop2{{.*}}-zu +__attribute__((target("no-apxf"))) +void f_no_apxf(void) {} diff --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c index 65ece3c27d299..a68fb06ec8684 100644 --- a/clang/test/Sema/attr-target.c +++ b/clang/test/Sema/attr-target.c @@ -35,6 +35,27 @@ void __attribute__((target("x86-64-v2"))) v2(void) {} int __attribute__((target("sha"))) good_target_but_not_for_fmv() { return 5; } +int __attribute__((target("apxf"))) apx_supported(void) { return 6; } +int __attribute__((target("no-apxf"))) no_apx_supported(void) { return 7; } + +// APXF sub-features should NOT be supported directly in target attribute +//expected-warning@+1 {{unsupported 'egpr' in the 'target' attribute string; 'target' attribute ignored}} +int __attribute__((target("egpr"))) egpr_not_supported(void) { return 8; } +//expected-warning@+1 {{unsupported 'ndd' in the 'target' attribute string; 'target' attribute ignored}} +int __attribute__((target("ndd"))) ndd_not_supported(void) { return 9; } +//expected-warning@+1 {{unsupported 'ccmp' in the 'target' attribute string; 'target' attribute ignored}} +int __attribute__((target("ccmp"))) ccmp_not_supported(void) { return 10; } +//expected-warning@+1 {{unsupported 'nf' in the 'target' attribute string; 'target' attribute ignored}} +int __attribute__((target("nf"))) nf_not_supported(void) { return 11; } +//expected-warning@+1 {{unsupported 'cf' in the 'target' attribute string; 'target' attribute ignored}} +int __attribute__((target("cf"))) cf_not_supported(void) { return 12; } +//expected-warning@+1 {{unsupported 'zu' in the 'target' attribute string; 'target' attribute ignored}} +int __attribute__((target("zu"))) zu_not_supported(void) { return 13; } +//expected-warning@+1 {{unsupported 'push2pop2' in the 'target' attribute string; 'target' attribute ignored}} +int __attribute__((target("push2pop2"))) push2pop2_not_supported(void) { return 14; } +//expected-warning@+1 {{unsupported 'ppx' in the 'target' attribute string; 'target' attribute ignored}} +int __attribute__((target("ppx"))) ppx_not_supported(void) { return 15; } + #elifdef __aarch64__ int __attribute__((target("sve,arch=armv8-a"))) foo(void) { return 4; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
