Skip to content

Commit 8a58407

Browse files
authored
[X86][EVEX512] Restrict attaching EVEX512 for default CPU only, NFCI (#65920)
Attaching EVEX512 is used to provide backward compatibility for legacy LLVM IR files, which didn't set EVEX512 feature explicitly. AVX512 and AVX10 targets have set or unset EVEX512 properly through X86.td. However, it's not feasible to list all AVX512 and AVX10 targets or their complementary set here to skip/restrict such code. Instead, we can restrict it for default CPU only. "generic" is used when "target-cpu" is not specified in IR, while "pentium4" and "x86-64" is the default CPU if "-march" is not specified in Clang for 32-bit and 64-bit targets respectively. This patch is no functional change intended, though it might affect scenarios like "-march=broadwell -mavx512bw", which looks like a misuse of "-march" and can be solved by changing to "-mtune=broadwell -mavx512bw".
1 parent 1d8a94c commit 8a58407

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

llvm/lib/Target/X86/X86Subtarget.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,23 @@ void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU,
268268
if (!FS.empty())
269269
FullFS = (Twine(FullFS) + "," + FS).str();
270270

271-
// Attach EVEX512 feature when we have AVX512 features and EVEX512 is not set.
272-
size_t posNoEVEX512 = FS.rfind("-evex512");
273-
// Make sure we won't be cheated by "-avx512fp16".
274-
size_t posNoAVX512F = FS.endswith("-avx512f") ? FS.size() - 8
275-
: FS.rfind("-avx512f,");
276-
size_t posEVEX512 = FS.rfind("+evex512");
277-
size_t posAVX512F = FS.rfind("+avx512"); // Any AVX512XXX will enable AVX512F.
278-
279-
if (posAVX512F != StringRef::npos &&
280-
(posNoAVX512F == StringRef::npos || posNoAVX512F < posAVX512F))
281-
if (posEVEX512 == StringRef::npos && posNoEVEX512 == StringRef::npos)
282-
FullFS += ",+evex512";
271+
// Attach EVEX512 feature when we have AVX512 features with a default CPU.
272+
// "pentium4" is default CPU for 32-bit targets.
273+
// "x86-64" is default CPU for 64-bit targets.
274+
if (CPU == "generic" || CPU == "pentium4" || CPU == "x86-64") {
275+
size_t posNoEVEX512 = FS.rfind("-evex512");
276+
// Make sure we won't be cheated by "-avx512fp16".
277+
size_t posNoAVX512F = FS.endswith("-avx512f") ? FS.size() - 8
278+
: FS.rfind("-avx512f,");
279+
size_t posEVEX512 = FS.rfind("+evex512");
280+
// Any AVX512XXX will enable AVX512F.
281+
size_t posAVX512F = FS.rfind("+avx512");
282+
283+
if (posAVX512F != StringRef::npos &&
284+
(posNoAVX512F == StringRef::npos || posNoAVX512F < posAVX512F))
285+
if (posEVEX512 == StringRef::npos && posNoEVEX512 == StringRef::npos)
286+
FullFS += ",+evex512";
287+
}
283288

284289
// Parse features string and set the CPU.
285290
ParseSubtargetFeatures(CPU, TuneCPU, FullFS);

0 commit comments

Comments
 (0)