[X86] Cleanup some CPUID usage in getAvailableFeatures.

We should make sure leaf 1 is available before accessing it. Same with leaf 0x80000001.

llvm-svn: 307462
This commit is contained in:
Craig Topper 2017-07-08 05:16:13 +00:00
parent 433c2f0859
commit bb8c799e1a
1 changed files with 10 additions and 5 deletions

View File

@ -987,8 +987,14 @@ static unsigned getAvailableFeatures(unsigned int ECX, unsigned int EDX,
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;