Skip to content

Commit b79e912

Browse files
committed
[Support] Don't check XCR0 when detecting avx512 on Darwin.
Darwin lazily saves the AVX512 context on first use [1]: instead of checking that it already does to figure out if the OS supports AVX512, trust that the kernel will do the right thing and always assume the context save support is available. [1] https://github.com/apple/darwin-xnu/blob/xnu-4903.221.2/osfmk/i386/fpu.c#L174 Reviewers: ab, RKSimon, craig.topper Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D70453 (cherry-picked from 82921bf)
1 parent 61e164c commit b79e912

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

llvm/lib/Support/Host.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,15 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
10271027
const unsigned AVXBits = (1 << 27) | (1 << 28);
10281028
bool HasAVX = ((ECX & AVXBits) == AVXBits) && !getX86XCR0(&EAX, &EDX) &&
10291029
((EAX & 0x6) == 0x6);
1030+
#if defined(__APPLE__)
1031+
// Darwin lazily saves the AVX512 context on first use: trust that the OS will
1032+
// save the AVX512 context if we use AVX512 instructions, even the bit is not
1033+
// set right now.
1034+
bool HasAVX512Save = true;
1035+
#else
1036+
// AVX512 requires additional context to be saved by the OS.
10301037
bool HasAVX512Save = HasAVX && ((EAX & 0xe0) == 0xe0);
1038+
#endif
10311039

10321040
if (HasAVX)
10331041
setFeature(X86::FEATURE_AVX);
@@ -1364,8 +1372,15 @@ bool sys::getHostCPUFeatures(StringMap<bool> &Features) {
13641372
// switch, then we have full AVX support.
13651373
bool HasAVXSave = ((ECX >> 27) & 1) && ((ECX >> 28) & 1) &&
13661374
!getX86XCR0(&EAX, &EDX) && ((EAX & 0x6) == 0x6);
1375+
#if defined(__APPLE__)
1376+
// Darwin lazily saves the AVX512 context on first use: trust that the OS will
1377+
// save the AVX512 context if we use AVX512 instructions, even the bit is not
1378+
// set right now.
1379+
bool HasAVX512Save = true;
1380+
#else
13671381
// AVX512 requires additional context to be saved by the OS.
13681382
bool HasAVX512Save = HasAVXSave && ((EAX & 0xe0) == 0xe0);
1383+
#endif
13691384

13701385
Features["avx"] = HasAVXSave;
13711386
Features["fma"] = ((ECX >> 12) & 1) && HasAVXSave;

0 commit comments

Comments
 (0)