Skip to content

Commit fabc690

Browse files
phoebewangronlieb
authored andcommitted
[X86][EVEX512] Restrict attaching EVEX512 for default CPU only, NFCI (llvm#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". Change-Id: Ia9ffa97056923b45f01e663a0df6c0c01fa69fe5
1 parent 07441d5 commit fabc690

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

llvm/lib/Target/X86/X86Subtarget.cpp

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

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

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

revert_patches.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ Johannes: breakage
66
[OpenMP][FIX] Move workaround code to avoid races
77
see smoke-fails, smoke-limbo, smoke, examples
88

9-
Revert/defer 8f5a18b6e58 Perf/lexer faster slow get char and size (#70543)
10-
to integrate into ASO
11-
129
Revert: waiting on pip install myst-parser
1310
b6ff03206 "[Documentation] Replace recommonmark by myst-parser
1411

15-
Revert: breaks qmcpack ISEL
16-
"[X86][EVEX512] Restrict attaching EVEX512 for default CPU only, NFCI (#65920)"
17-
1812
Johannes: revert breaks 3 sollve tests
1913
[OpenMP] Simplify parallel reductions (#70983)
2014
test_loop_reduction_and_device.c

0 commit comments

Comments
 (0)