[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
https://github.com/FreddyLeaf closed https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
FreddyLeaf wrote: Thank you both for all of the review! https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
https://github.com/KanRobert approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
FreddyLeaf wrote: ping https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -265,6 +265,7 @@ X86_MICROARCH_LEVEL(X86_64_BASELINE,"x86-64", 95) X86_MICROARCH_LEVEL(X86_64_V2, "x86-64-v2",96) X86_MICROARCH_LEVEL(X86_64_V3, "x86-64-v3",97) X86_MICROARCH_LEVEL(X86_64_V4, "x86-64-v4",98) +X86_MICROARCH_LEVEL(APXF, "apxf",111) FreddyLeaf wrote: done. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
https://github.com/FreddyLeaf edited https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
https://github.com/FreddyLeaf updated https://github.com/llvm/llvm-project/pull/80636 >From b131b0971d5c38a29c954b37c0da8fb3177e5c92 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Mon, 5 Feb 2024 14:07:29 +0800 Subject: [PATCH 1/6] [X86] Support APXF to enable __builtin_cpu_supports. --- clang/test/CodeGen/target-builtin-noerror.c| 1 + compiler-rt/lib/builtins/cpu_model/x86.c | 4 +++- llvm/include/llvm/TargetParser/X86TargetParser.def | 3 ++- llvm/lib/TargetParser/Host.cpp | 1 + llvm/lib/TargetParser/X86TargetParser.cpp | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/test/CodeGen/target-builtin-noerror.c b/clang/test/CodeGen/target-builtin-noerror.c index 9608b5f37baaae..b438e50848a4b6 100644 --- a/clang/test/CodeGen/target-builtin-noerror.c +++ b/clang/test/CodeGen/target-builtin-noerror.c @@ -141,6 +141,7 @@ void verifyfeaturestrings(void) { (void)__builtin_cpu_supports("sm3"); (void)__builtin_cpu_supports("sha512"); (void)__builtin_cpu_supports("sm4"); + (void)__builtin_cpu_supports("apxf"); (void)__builtin_cpu_supports("usermsr"); (void)__builtin_cpu_supports("avx10.1-256"); (void)__builtin_cpu_supports("avx10.1-512"); diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 1afa468c4ae8c1..35375c6e8d55b6 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -217,7 +217,7 @@ enum ProcessorFeatures { FEATURE_SM3, FEATURE_SHA512, FEATURE_SM4, - // FEATURE_APXF, + FEATURE_APXF, FEATURE_USERMSR = 112, FEATURE_AVX10_1_256, FEATURE_AVX10_1_512, @@ -983,6 +983,8 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, setFeature(FEATURE_USERMSR); if (HasLeaf7Subleaf1 && ((EDX >> 19) & 1)) setFeature(FEATURE_AVX10_1_256); + if (HasLeaf7Subleaf1 && ((EDX >> 21) & 1)) +setFeature(FEATURE_APXF); unsigned MaxLevel; getX86CpuIDAndInfo(0, , , , ); diff --git a/llvm/include/llvm/TargetParser/X86TargetParser.def b/llvm/include/llvm/TargetParser/X86TargetParser.def index 4c630c1eb06e8c..ec52062a2baacf 100644 --- a/llvm/include/llvm/TargetParser/X86TargetParser.def +++ b/llvm/include/llvm/TargetParser/X86TargetParser.def @@ -248,10 +248,11 @@ X86_FEATURE_COMPAT(AVXVNNIINT16,"avxvnniint16", 0) X86_FEATURE_COMPAT(SM3, "sm3",0) X86_FEATURE_COMPAT(SHA512, "sha512", 0) X86_FEATURE_COMPAT(SM4, "sm4",0) -X86_FEATURE (EGPR,"egpr") +X86_FEATURE_COMPAT(APXF,"apxf", 0) X86_FEATURE_COMPAT(USERMSR, "usermsr",0) X86_FEATURE_COMPAT(AVX10_1, "avx10.1-256",0) X86_FEATURE_COMPAT(AVX10_1_512, "avx10.1-512",0) +X86_FEATURE (EGPR,"egpr") X86_FEATURE (EVEX512, "evex512") X86_FEATURE (CF, "cf") // These features aren't really CPU features, but the frontend can set them. diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index f1197c29655380..233ee12a000962 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); bool HasLeafD = MaxLevel >= 0xd && !getX86CpuIDAndInfoEx(0xd, 0x1, , , , ); diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp b/llvm/lib/TargetParser/X86TargetParser.cpp index 21f46f576490a8..ea1f8517bb3329 100644 --- a/llvm/lib/TargetParser/X86TargetParser.cpp +++ b/llvm/lib/TargetParser/X86TargetParser.cpp @@ -633,6 +633,7 @@ constexpr FeatureBitset ImpliedFeaturesPPX = {}; constexpr FeatureBitset ImpliedFeaturesNDD = {}; constexpr FeatureBitset ImpliedFeaturesCCMP = {}; constexpr FeatureBitset ImpliedFeaturesCF = {}; +constexpr FeatureBitset ImpliedFeaturesAPXF = {}; constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = { #define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM}, >From a1ecdf5fe54cb03045748e3d49f23e24e9428973 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Tue, 6 Feb 2024 17:19:28 +0800 Subject: [PATCH 2/6] misc --- compiler-rt/lib/builtins/cpu_model/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 35375c6e8d55b6..7e8acb3e73eda9 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -218,7 +218,7 @@ enum ProcessorFeatures { FEATURE_SHA512, FEATURE_SM4, FEATURE_APXF, - FEATURE_USERMSR =
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -265,6 +265,7 @@ X86_MICROARCH_LEVEL(X86_64_BASELINE,"x86-64", 95) X86_MICROARCH_LEVEL(X86_64_V2, "x86-64-v2",96) X86_MICROARCH_LEVEL(X86_64_V3, "x86-64-v3",97) X86_MICROARCH_LEVEL(X86_64_V4, "x86-64-v4",98) +X86_MICROARCH_LEVEL(APXF, "apxf",111) KanRobert wrote: Add the link in the description? https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -983,6 +983,8 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, setFeature(FEATURE_USERMSR); if (HasLeaf7Subleaf1 && ((EDX >> 19) & 1)) setFeature(FEATURE_AVX10_1_256); + if (HasLeaf7Subleaf1 && ((EDX >> 21) & 1)) FreddyLeaf wrote: Done. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -219,6 +219,7 @@ #define bit_PREFETCHI 0x4000 #define bit_USERMSR 0x8000 #define bit_AVX10 0x0008 +#define bit_APXF 0x0020 FreddyLeaf wrote: Done. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
https://github.com/FreddyLeaf edited https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
https://github.com/FreddyLeaf edited https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -265,6 +265,7 @@ X86_MICROARCH_LEVEL(X86_64_BASELINE,"x86-64", 95) X86_MICROARCH_LEVEL(X86_64_V2, "x86-64-v2",96) X86_MICROARCH_LEVEL(X86_64_V3, "x86-64-v3",97) X86_MICROARCH_LEVEL(X86_64_V4, "x86-64-v4",98) +X86_MICROARCH_LEVEL(APXF, "apxf",111) FreddyLeaf wrote: this is to align with libgcc https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -219,6 +219,7 @@ #define bit_PREFETCHI 0x4000 #define bit_USERMSR 0x8000 #define bit_AVX10 0x0008 +#define bit_APXF 0x0020 KanRobert wrote: Where is the number from? Add the link in your description of the PR. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -265,6 +265,7 @@ X86_MICROARCH_LEVEL(X86_64_BASELINE,"x86-64", 95) X86_MICROARCH_LEVEL(X86_64_V2, "x86-64-v2",96) X86_MICROARCH_LEVEL(X86_64_V3, "x86-64-v3",97) X86_MICROARCH_LEVEL(X86_64_V4, "x86-64-v4",98) +X86_MICROARCH_LEVEL(APXF, "apxf",111) KanRobert wrote: Where is 111 from? https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -983,6 +983,8 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, setFeature(FEATURE_USERMSR); if (HasLeaf7Subleaf1 && ((EDX >> 19) & 1)) setFeature(FEATURE_AVX10_1_256); + if (HasLeaf7Subleaf1 && ((EDX >> 21) & 1)) KanRobert wrote: Add SPEC sentence in your description. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,12 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["egpr"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["push2pop2"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["ppx"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["ndd"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["ccmp"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["cf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); FreddyLeaf wrote: [fd73a2a](https://github.com/llvm/llvm-project/pull/80636/commits/fd73a2a447e90ae6d4270bfd9fc958343995138c) https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
https://github.com/FreddyLeaf updated https://github.com/llvm/llvm-project/pull/80636 >From b131b0971d5c38a29c954b37c0da8fb3177e5c92 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Mon, 5 Feb 2024 14:07:29 +0800 Subject: [PATCH 1/5] [X86] Support APXF to enable __builtin_cpu_supports. --- clang/test/CodeGen/target-builtin-noerror.c| 1 + compiler-rt/lib/builtins/cpu_model/x86.c | 4 +++- llvm/include/llvm/TargetParser/X86TargetParser.def | 3 ++- llvm/lib/TargetParser/Host.cpp | 1 + llvm/lib/TargetParser/X86TargetParser.cpp | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/test/CodeGen/target-builtin-noerror.c b/clang/test/CodeGen/target-builtin-noerror.c index 9608b5f37baaae..b438e50848a4b6 100644 --- a/clang/test/CodeGen/target-builtin-noerror.c +++ b/clang/test/CodeGen/target-builtin-noerror.c @@ -141,6 +141,7 @@ void verifyfeaturestrings(void) { (void)__builtin_cpu_supports("sm3"); (void)__builtin_cpu_supports("sha512"); (void)__builtin_cpu_supports("sm4"); + (void)__builtin_cpu_supports("apxf"); (void)__builtin_cpu_supports("usermsr"); (void)__builtin_cpu_supports("avx10.1-256"); (void)__builtin_cpu_supports("avx10.1-512"); diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 1afa468c4ae8c1..35375c6e8d55b6 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -217,7 +217,7 @@ enum ProcessorFeatures { FEATURE_SM3, FEATURE_SHA512, FEATURE_SM4, - // FEATURE_APXF, + FEATURE_APXF, FEATURE_USERMSR = 112, FEATURE_AVX10_1_256, FEATURE_AVX10_1_512, @@ -983,6 +983,8 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, setFeature(FEATURE_USERMSR); if (HasLeaf7Subleaf1 && ((EDX >> 19) & 1)) setFeature(FEATURE_AVX10_1_256); + if (HasLeaf7Subleaf1 && ((EDX >> 21) & 1)) +setFeature(FEATURE_APXF); unsigned MaxLevel; getX86CpuIDAndInfo(0, , , , ); diff --git a/llvm/include/llvm/TargetParser/X86TargetParser.def b/llvm/include/llvm/TargetParser/X86TargetParser.def index 4c630c1eb06e8c..ec52062a2baacf 100644 --- a/llvm/include/llvm/TargetParser/X86TargetParser.def +++ b/llvm/include/llvm/TargetParser/X86TargetParser.def @@ -248,10 +248,11 @@ X86_FEATURE_COMPAT(AVXVNNIINT16,"avxvnniint16", 0) X86_FEATURE_COMPAT(SM3, "sm3",0) X86_FEATURE_COMPAT(SHA512, "sha512", 0) X86_FEATURE_COMPAT(SM4, "sm4",0) -X86_FEATURE (EGPR,"egpr") +X86_FEATURE_COMPAT(APXF,"apxf", 0) X86_FEATURE_COMPAT(USERMSR, "usermsr",0) X86_FEATURE_COMPAT(AVX10_1, "avx10.1-256",0) X86_FEATURE_COMPAT(AVX10_1_512, "avx10.1-512",0) +X86_FEATURE (EGPR,"egpr") X86_FEATURE (EVEX512, "evex512") X86_FEATURE (CF, "cf") // These features aren't really CPU features, but the frontend can set them. diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index f1197c29655380..233ee12a000962 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); bool HasLeafD = MaxLevel >= 0xd && !getX86CpuIDAndInfoEx(0xd, 0x1, , , , ); diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp b/llvm/lib/TargetParser/X86TargetParser.cpp index 21f46f576490a8..ea1f8517bb3329 100644 --- a/llvm/lib/TargetParser/X86TargetParser.cpp +++ b/llvm/lib/TargetParser/X86TargetParser.cpp @@ -633,6 +633,7 @@ constexpr FeatureBitset ImpliedFeaturesPPX = {}; constexpr FeatureBitset ImpliedFeaturesNDD = {}; constexpr FeatureBitset ImpliedFeaturesCCMP = {}; constexpr FeatureBitset ImpliedFeaturesCF = {}; +constexpr FeatureBitset ImpliedFeaturesAPXF = {}; constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = { #define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM}, >From a1ecdf5fe54cb03045748e3d49f23e24e9428973 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Tue, 6 Feb 2024 17:19:28 +0800 Subject: [PATCH 2/5] misc --- compiler-rt/lib/builtins/cpu_model/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 35375c6e8d55b6..7e8acb3e73eda9 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -218,7 +218,7 @@ enum ProcessorFeatures { FEATURE_SHA512, FEATURE_SM4, FEATURE_APXF, - FEATURE_USERMSR =
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
FreddyLeaf wrote: > You may also need to transfer "apxf" feature into subfeatures here > https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/X86.cpp#L106 Thanks for pointing out! This looks like the change required by supporting attribute((target("apxf"))). While that supports require other relate changes such as adding supports for apxf in X86TargetInfo::isValidFeatureName. I prefer to do it in another PR. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
phoebewang wrote: You may also need to transfer "apxf" feature into subfeatures here https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/X86.cpp#L106 https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,12 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["egpr"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["push2pop2"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["ppx"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["ndd"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["ccmp"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); + Features["cf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); phoebewang wrote: You should use a variable like `bool HasAPXF = HasLeaf7Subleaf1 && ((EDX >> 21) & 1);` https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
FreddyLeaf wrote: After [fa42b33](https://github.com/llvm/llvm-project/pull/80636/commits/fa42b33d62227bd88cc5d63431244d0caac1e286) 1. An error will be thrown out if compiling `__builtin_cpu_supports("egpr")` 2. __attribute__((__target__("apxf"))) is not supported in this patch, no matter amend features or FMV. 3. __attribute__((__target__("egpr,cf"))) is already supported before this PR. I think 3rd can be a workaround of 2nd, and gcc also hasn't supported FMV for "apxf". https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
https://github.com/FreddyLeaf updated https://github.com/llvm/llvm-project/pull/80636 >From b131b0971d5c38a29c954b37c0da8fb3177e5c92 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Mon, 5 Feb 2024 14:07:29 +0800 Subject: [PATCH 1/4] [X86] Support APXF to enable __builtin_cpu_supports. --- clang/test/CodeGen/target-builtin-noerror.c| 1 + compiler-rt/lib/builtins/cpu_model/x86.c | 4 +++- llvm/include/llvm/TargetParser/X86TargetParser.def | 3 ++- llvm/lib/TargetParser/Host.cpp | 1 + llvm/lib/TargetParser/X86TargetParser.cpp | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/test/CodeGen/target-builtin-noerror.c b/clang/test/CodeGen/target-builtin-noerror.c index 9608b5f37baaae..b438e50848a4b6 100644 --- a/clang/test/CodeGen/target-builtin-noerror.c +++ b/clang/test/CodeGen/target-builtin-noerror.c @@ -141,6 +141,7 @@ void verifyfeaturestrings(void) { (void)__builtin_cpu_supports("sm3"); (void)__builtin_cpu_supports("sha512"); (void)__builtin_cpu_supports("sm4"); + (void)__builtin_cpu_supports("apxf"); (void)__builtin_cpu_supports("usermsr"); (void)__builtin_cpu_supports("avx10.1-256"); (void)__builtin_cpu_supports("avx10.1-512"); diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 1afa468c4ae8c1..35375c6e8d55b6 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -217,7 +217,7 @@ enum ProcessorFeatures { FEATURE_SM3, FEATURE_SHA512, FEATURE_SM4, - // FEATURE_APXF, + FEATURE_APXF, FEATURE_USERMSR = 112, FEATURE_AVX10_1_256, FEATURE_AVX10_1_512, @@ -983,6 +983,8 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, setFeature(FEATURE_USERMSR); if (HasLeaf7Subleaf1 && ((EDX >> 19) & 1)) setFeature(FEATURE_AVX10_1_256); + if (HasLeaf7Subleaf1 && ((EDX >> 21) & 1)) +setFeature(FEATURE_APXF); unsigned MaxLevel; getX86CpuIDAndInfo(0, , , , ); diff --git a/llvm/include/llvm/TargetParser/X86TargetParser.def b/llvm/include/llvm/TargetParser/X86TargetParser.def index 4c630c1eb06e8c..ec52062a2baacf 100644 --- a/llvm/include/llvm/TargetParser/X86TargetParser.def +++ b/llvm/include/llvm/TargetParser/X86TargetParser.def @@ -248,10 +248,11 @@ X86_FEATURE_COMPAT(AVXVNNIINT16,"avxvnniint16", 0) X86_FEATURE_COMPAT(SM3, "sm3",0) X86_FEATURE_COMPAT(SHA512, "sha512", 0) X86_FEATURE_COMPAT(SM4, "sm4",0) -X86_FEATURE (EGPR,"egpr") +X86_FEATURE_COMPAT(APXF,"apxf", 0) X86_FEATURE_COMPAT(USERMSR, "usermsr",0) X86_FEATURE_COMPAT(AVX10_1, "avx10.1-256",0) X86_FEATURE_COMPAT(AVX10_1_512, "avx10.1-512",0) +X86_FEATURE (EGPR,"egpr") X86_FEATURE (EVEX512, "evex512") X86_FEATURE (CF, "cf") // These features aren't really CPU features, but the frontend can set them. diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index f1197c29655380..233ee12a000962 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); bool HasLeafD = MaxLevel >= 0xd && !getX86CpuIDAndInfoEx(0xd, 0x1, , , , ); diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp b/llvm/lib/TargetParser/X86TargetParser.cpp index 21f46f576490a8..ea1f8517bb3329 100644 --- a/llvm/lib/TargetParser/X86TargetParser.cpp +++ b/llvm/lib/TargetParser/X86TargetParser.cpp @@ -633,6 +633,7 @@ constexpr FeatureBitset ImpliedFeaturesPPX = {}; constexpr FeatureBitset ImpliedFeaturesNDD = {}; constexpr FeatureBitset ImpliedFeaturesCCMP = {}; constexpr FeatureBitset ImpliedFeaturesCF = {}; +constexpr FeatureBitset ImpliedFeaturesAPXF = {}; constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = { #define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM}, >From a1ecdf5fe54cb03045748e3d49f23e24e9428973 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Tue, 6 Feb 2024 17:19:28 +0800 Subject: [PATCH 2/4] misc --- compiler-rt/lib/builtins/cpu_model/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 35375c6e8d55b6..7e8acb3e73eda9 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -218,7 +218,7 @@ enum ProcessorFeatures { FEATURE_SHA512, FEATURE_SM4, FEATURE_APXF, - FEATURE_USERMSR =
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); FreddyLeaf wrote: Yeah, that's another problem. For attribute/target, it seems more reasonable to enable as "egpr" instead of "apxf" because apx needs such fine-grained enabling. We need to discuss with gcc on this. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); phoebewang wrote: I think you cannot actually enable APX features when using `__attribute__((__target__("apxf")))` either. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); FreddyLeaf wrote: Emm, I happened to find an issue with this patch. ``` $ clang -march=native foo.c -S -emit-llvm '-apxf' is not a recognized feature for this target (ignoring feature) ``` It turns out even not adding logics in X86TargetInfo::hasFeature it will still return false for "apxf". I also found "-egpr" is not generated. How did you handle this? https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); KanRobert wrote: > if llc read "apxf" in attribute, I think a warning will be given like: > > ``` > '+apxf' is not a recognized feature for this target (ignoring feature) > ``` Did you check the behavior w/ this patch? https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); FreddyLeaf wrote: > My understanding is "apxf" here is used by front-end for FMV, right? Yes, not only FMV, but also __builtin_cpu_supports. > What would happen if there is "apxf" in the IR after this patch? if llc read "apxf" in attribute, I think a warning will be given like: ``` '+apxf' is not a recognized feature for this target (ignoring feature) ``` But such attribute won't be generated from frontend, because we didn't add logics for "apxf" in X86TargetInfo::hasFeature. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); KanRobert wrote: My understanding is "apxf" here is used by front-end for FMV, right? What would happen if there is "apxf" in the IR after this patch? https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
https://github.com/FreddyLeaf updated https://github.com/llvm/llvm-project/pull/80636 >From b131b0971d5c38a29c954b37c0da8fb3177e5c92 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Mon, 5 Feb 2024 14:07:29 +0800 Subject: [PATCH 1/3] [X86] Support APXF to enable __builtin_cpu_supports. --- clang/test/CodeGen/target-builtin-noerror.c| 1 + compiler-rt/lib/builtins/cpu_model/x86.c | 4 +++- llvm/include/llvm/TargetParser/X86TargetParser.def | 3 ++- llvm/lib/TargetParser/Host.cpp | 1 + llvm/lib/TargetParser/X86TargetParser.cpp | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/test/CodeGen/target-builtin-noerror.c b/clang/test/CodeGen/target-builtin-noerror.c index 9608b5f37baaae..b438e50848a4b6 100644 --- a/clang/test/CodeGen/target-builtin-noerror.c +++ b/clang/test/CodeGen/target-builtin-noerror.c @@ -141,6 +141,7 @@ void verifyfeaturestrings(void) { (void)__builtin_cpu_supports("sm3"); (void)__builtin_cpu_supports("sha512"); (void)__builtin_cpu_supports("sm4"); + (void)__builtin_cpu_supports("apxf"); (void)__builtin_cpu_supports("usermsr"); (void)__builtin_cpu_supports("avx10.1-256"); (void)__builtin_cpu_supports("avx10.1-512"); diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 1afa468c4ae8c1..35375c6e8d55b6 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -217,7 +217,7 @@ enum ProcessorFeatures { FEATURE_SM3, FEATURE_SHA512, FEATURE_SM4, - // FEATURE_APXF, + FEATURE_APXF, FEATURE_USERMSR = 112, FEATURE_AVX10_1_256, FEATURE_AVX10_1_512, @@ -983,6 +983,8 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, setFeature(FEATURE_USERMSR); if (HasLeaf7Subleaf1 && ((EDX >> 19) & 1)) setFeature(FEATURE_AVX10_1_256); + if (HasLeaf7Subleaf1 && ((EDX >> 21) & 1)) +setFeature(FEATURE_APXF); unsigned MaxLevel; getX86CpuIDAndInfo(0, , , , ); diff --git a/llvm/include/llvm/TargetParser/X86TargetParser.def b/llvm/include/llvm/TargetParser/X86TargetParser.def index 4c630c1eb06e8c..ec52062a2baacf 100644 --- a/llvm/include/llvm/TargetParser/X86TargetParser.def +++ b/llvm/include/llvm/TargetParser/X86TargetParser.def @@ -248,10 +248,11 @@ X86_FEATURE_COMPAT(AVXVNNIINT16,"avxvnniint16", 0) X86_FEATURE_COMPAT(SM3, "sm3",0) X86_FEATURE_COMPAT(SHA512, "sha512", 0) X86_FEATURE_COMPAT(SM4, "sm4",0) -X86_FEATURE (EGPR,"egpr") +X86_FEATURE_COMPAT(APXF,"apxf", 0) X86_FEATURE_COMPAT(USERMSR, "usermsr",0) X86_FEATURE_COMPAT(AVX10_1, "avx10.1-256",0) X86_FEATURE_COMPAT(AVX10_1_512, "avx10.1-512",0) +X86_FEATURE (EGPR,"egpr") X86_FEATURE (EVEX512, "evex512") X86_FEATURE (CF, "cf") // These features aren't really CPU features, but the frontend can set them. diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index f1197c29655380..233ee12a000962 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); bool HasLeafD = MaxLevel >= 0xd && !getX86CpuIDAndInfoEx(0xd, 0x1, , , , ); diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp b/llvm/lib/TargetParser/X86TargetParser.cpp index 21f46f576490a8..ea1f8517bb3329 100644 --- a/llvm/lib/TargetParser/X86TargetParser.cpp +++ b/llvm/lib/TargetParser/X86TargetParser.cpp @@ -633,6 +633,7 @@ constexpr FeatureBitset ImpliedFeaturesPPX = {}; constexpr FeatureBitset ImpliedFeaturesNDD = {}; constexpr FeatureBitset ImpliedFeaturesCCMP = {}; constexpr FeatureBitset ImpliedFeaturesCF = {}; +constexpr FeatureBitset ImpliedFeaturesAPXF = {}; constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = { #define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM}, >From a1ecdf5fe54cb03045748e3d49f23e24e9428973 Mon Sep 17 00:00:00 2001 From: Freddy Ye Date: Tue, 6 Feb 2024 17:19:28 +0800 Subject: [PATCH 2/3] misc --- compiler-rt/lib/builtins/cpu_model/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 35375c6e8d55b6..7e8acb3e73eda9 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -218,7 +218,7 @@ enum ProcessorFeatures { FEATURE_SHA512, FEATURE_SM4, FEATURE_APXF, - FEATURE_USERMSR =
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); FreddyLeaf wrote: This patch defined one in clang through llvm/include/llvm/TargetParser/X86TargetParser.def. I think it's ok to do so. https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
@@ -1845,6 +1845,7 @@ bool sys::getHostCPUFeatures(StringMap ) { Features["prefetchi"] = HasLeaf7Subleaf1 && ((EDX >> 14) & 1); Features["usermsr"] = HasLeaf7Subleaf1 && ((EDX >> 15) & 1); Features["avx10.1-256"] = HasLeaf7Subleaf1 && ((EDX >> 19) & 1); + Features["apxf"] = HasLeaf7Subleaf1 && ((EDX >> 21) & 1); phoebewang wrote: I don't think we have a `apxf` feature in LLVM, should it be `egpr`? https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [X86] Support APXF to enable __builtin_cpu_supports. (PR #80636)
FreddyLeaf wrote: ping for review https://github.com/llvm/llvm-project/pull/80636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits