[llvm] r307462 - [X86] Cleanup some CPUID usage in getAvailableFeatures.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 7 22:16:13 PDT 2017
Author: ctopper
Date: Fri Jul 7 22:16:13 2017
New Revision: 307462
URL: http://llvm.org/viewvc/llvm-project?rev=307462&view=rev
Log:
[X86] Cleanup some CPUID usage in getAvailableFeatures.
We should make sure leaf 1 is available before accessing it. Same with leaf 0x80000001.
Modified:
llvm/trunk/lib/Support/Host.cpp
Modified: llvm/trunk/lib/Support/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Host.cpp?rev=307462&r1=307461&r2=307462&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Host.cpp (original)
+++ llvm/trunk/lib/Support/Host.cpp Fri Jul 7 22:16:13 2017
@@ -987,8 +987,14 @@ static unsigned getAvailableFeatures(uns
Features |= (HasAVX512Save << FEATURE_AVX512SAVE);
Features |= (HasADX << FEATURE_ADX);
- getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
- Features |= (((EDX >> 29) & 0x1) << FEATURE_EM64T);
+ unsigned MaxExtLevel;
+ getX86CpuIDAndInfo(0x80000000, &MaxExtLevel, &EBX, &ECX, &EDX);
+
+ bool HasExtLeaf1 = MaxExtLevel >= 0x80000001 &&
+ !getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
+ if (HasExtLeaf1)
+ Features |= (((EDX >> 29) & 0x1) << FEATURE_EM64T);
+
return Features;
}
@@ -1004,10 +1010,9 @@ StringRef sys::getHostCPUName() {
if(!isCpuIdSupported())
return "generic";
#endif
- if (getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX))
- return "generic";
- if (getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
+ if (getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX) || MaxLeaf < 1)
return "generic";
+ getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
unsigned Brand_id = EBX & 0xff;
unsigned Family = 0, Model = 0;
More information about the llvm-commits
mailing list