From 2c9b39efcb20aa2a89aff9676a236f9582d5a952 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 21 Oct 2011 16:32:32 +0200 Subject: [PATCH] re PR driver/50740 (CPUID leaf 7 for BMI/BMI2/AVX2 feature detection not qualified with max_level and doesn't use subleaf) PR target/50740 * config/i386/driver-i386.c (host_detect_local_cpu): Do cpuid 7 only if max_level allows that. testsuite/ChangeLog: PR target/50740 * gcc.target/i386/avx2-check.h (main): Check CPUID level correctly. * gcc.target/i386/bmi2-check.h: Ditto. From-SVN: r180304 --- gcc/ChangeLog | 10 ++++++++-- gcc/config/i386/driver-i386.c | 15 +++++++++------ gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/gcc.target/i386/avx2-check.h | 3 +++ gcc/testsuite/gcc.target/i386/bmi2-check.h | 3 +++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 16da4d66a0f3..86658cb2a95b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2011-10-21 H.J. Lu + Kirill Yukhin + + * config/i386/driver-i386.c (host_detect_local_cpu): Do cpuid 7 only + if max_level allows that. + 2011-10-21 Bernd Schmidt * reg-notes.def (DEP_CONTROL): New. @@ -117,7 +123,8 @@ 2011-10-21 Jan Hubicka * cgraph.c (dump_cgraph_node): Dump alias flag. - * cgraphunit.c (handle_alias_pairs): Handle weakrefs with no destination. + * cgraphunit.c (handle_alias_pairs): Handle weakrefs with + no destination. (get_alias_symbol): New function. (output_weakrefs): Output also weakrefs with no destinatoin. (lto_output_node): Output weakref alias flag when at function boundary. @@ -125,7 +132,6 @@ 2011-10-21 Andrew Stubbs PR target/50809 - * config/arm/driver-arm.c (vendors): Make static. 2011-10-21 Uros Bizjak diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c index 8107ecee7c96..5f14c76fe55e 100644 --- a/gcc/config/i386/driver-i386.c +++ b/gcc/config/i386/driver-i386.c @@ -451,6 +451,15 @@ const char *host_detect_local_cpu (int argc, const char **argv) has_sse = edx & bit_SSE; has_sse2 = edx & bit_SSE2; + if (max_level >= 7) + { + __cpuid_count (7, 0, eax, ebx, ecx, edx); + + has_bmi = ebx & bit_BMI; + has_avx2 = ebx & bit_AVX2; + has_bmi2 = ebx & bit_BMI2; + } + /* Check cpuid level of extended features. */ __cpuid (0x80000000, ext_level, ebx, ecx, edx); @@ -470,12 +479,6 @@ const char *host_detect_local_cpu (int argc, const char **argv) has_longmode = edx & bit_LM; has_3dnowp = edx & bit_3DNOWP; has_3dnow = edx & bit_3DNOW; - - __cpuid (0x7, eax, ebx, ecx, edx); - - has_bmi = ebx & bit_BMI; - has_avx2 = ebx & bit_AVX2; - has_bmi2 = ebx & bit_BMI2; } if (!arch) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a1b2752c45f4..ef3404611df7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2011-10-21 H.J. Lu + Kirill Yukhin + + PR target/50740 + * gcc.target/i386/avx2-check.h (main): Check CPUID level correctly. + * gcc.target/i386/bmi2-check.h: Ditto. + 2011-10-21 Ville Voutilainen PR c++/50811 diff --git a/gcc/testsuite/gcc.target/i386/avx2-check.h b/gcc/testsuite/gcc.target/i386/avx2-check.h index 22c9b39da458..424335dbb5ea 100644 --- a/gcc/testsuite/gcc.target/i386/avx2-check.h +++ b/gcc/testsuite/gcc.target/i386/avx2-check.h @@ -21,6 +21,9 @@ main () /* Run AVX2 test only if host has AVX2 support. */ if ((ecx & bit_OSXSAVE) == (bit_OSXSAVE)) { + if (__get_cpuid_max (0, NULL) < 7) + return 0; + __cpuid_count (7, 0, eax, ebx, ecx, edx); if ((avx_os_support ()) && ((ebx & bit_AVX2) == bit_AVX2)) diff --git a/gcc/testsuite/gcc.target/i386/bmi2-check.h b/gcc/testsuite/gcc.target/i386/bmi2-check.h index 5ffce44fc6ed..c933a49f2817 100644 --- a/gcc/testsuite/gcc.target/i386/bmi2-check.h +++ b/gcc/testsuite/gcc.target/i386/bmi2-check.h @@ -17,6 +17,9 @@ main () { unsigned int eax, ebx, ecx, edx; + if (__get_cpuid_max (0, NULL) < 7) + return 0; + __cpuid_count (7, 0, eax, ebx, ecx, edx); /* Run BMI2 test only if host has BMI2 support. */ -- 2.47.2