[clang] [llvm] [X86][Driver] Do not add `-evex512` for `-march=native` when the target doesn't support AVX512 (PR #91694)
Phoebe Wang via cfe-commits
cfe-commits at lists.llvm.org
Thu May 9 21:03:17 PDT 2024
https://github.com/phoebewang updated https://github.com/llvm/llvm-project/pull/91694
>From 6ea15aa0ee6726cad8dccff10155f058afa0f013 Mon Sep 17 00:00:00 2001
From: Phoebe Wang <phoebe.wang at intel.com>
Date: Fri, 10 May 2024 11:21:41 +0800
Subject: [PATCH 1/2] [X86][Driver] Do not add `-evex512` for `-march=native`
when the target doesn't support AVX512
Users want `-march=sandybridge -mavx512f -mavx512vl` behaves the same as
`-march=native -mavx512f -mavx512vl` on a sandybridge target.
Fixes: #91076
---
clang/lib/Driver/ToolChains/Arch/X86.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index 53e26a9f8e229..c6d97ef4e971a 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -132,10 +132,14 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
if (StringRef(A->getValue()) == "native") {
llvm::StringMap<bool> HostFeatures;
- if (llvm::sys::getHostCPUFeatures(HostFeatures))
- for (auto &F : HostFeatures)
+ if (llvm::sys::getHostCPUFeatures(HostFeatures)) {
+ for (auto &F : HostFeatures) {
+ if (!F.second && F.first() == "evex512")
+ continue;
Features.push_back(
Args.MakeArgString((F.second ? "+" : "-") + F.first()));
+ }
+ }
}
}
>From d50ae3b317839f5603b091aa029414b3c3c42259 Mon Sep 17 00:00:00 2001
From: Phoebe Wang <phoebe.wang at intel.com>
Date: Fri, 10 May 2024 12:02:09 +0800
Subject: [PATCH 2/2] Address review comment
---
clang/lib/Driver/ToolChains/Arch/X86.cpp | 8 ++------
llvm/lib/TargetParser/Host.cpp | 3 ++-
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index c6d97ef4e971a..53e26a9f8e229 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -132,14 +132,10 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
if (StringRef(A->getValue()) == "native") {
llvm::StringMap<bool> HostFeatures;
- if (llvm::sys::getHostCPUFeatures(HostFeatures)) {
- for (auto &F : HostFeatures) {
- if (!F.second && F.first() == "evex512")
- continue;
+ if (llvm::sys::getHostCPUFeatures(HostFeatures))
+ for (auto &F : HostFeatures)
Features.push_back(
Args.MakeArgString((F.second ? "+" : "-") + F.first()));
- }
- }
}
}
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 834f4536f93ac..c5156c6cb802c 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1802,7 +1802,8 @@ bool sys::getHostCPUFeatures(StringMap<bool> &Features) {
Features["rtm"] = HasLeaf7 && ((EBX >> 11) & 1);
// AVX512 is only supported if the OS supports the context save for it.
Features["avx512f"] = HasLeaf7 && ((EBX >> 16) & 1) && HasAVX512Save;
- Features["evex512"] = Features["avx512f"];
+ if (Features["avx512f"])
+ Features["evex512"] = true;
Features["avx512dq"] = HasLeaf7 && ((EBX >> 17) & 1) && HasAVX512Save;
Features["rdseed"] = HasLeaf7 && ((EBX >> 18) & 1);
Features["adx"] = HasLeaf7 && ((EBX >> 19) & 1);
More information about the cfe-commits
mailing list