[X86] Workaround possible CPUID bug in Sandy Bridge.
authorCraig Topper <craig.topper@sifive.com>
Thu, 3 Aug 2023 15:12:00 +0000 (08:12 -0700)
committerTobias Hieta <tobias@hieta.se>
Fri, 4 Aug 2023 05:51:01 +0000 (07:51 +0200)
commitd1603c3d902ad1a469261ce6a2b302e6d783f55c
treef8b2ada3b3da5379dd745e54e957d91311505dbe
parent51a4700a3f5bad74d670a39e6daf54e6e545189c
[X86] Workaround possible CPUID bug in Sandy Bridge.

Don't access leaf 7 subleaf 1 unless subleaf 0 says it is
supported via EAX.

Intel documentation says invalid subleaves return 0. We had been
relying on that behavior instead of checking the max sublef number.

It appears that some Sandy Bridge CPUs return at least the subleaf 0
EDX value for subleaf 1. Best guess is that this is a bug in a
microcode patch since all of the bits we're seeing set in EDX were
introduced after Sandy Bridge was originally released.

This is causing avxvnniint16 to be incorrectly enabled with -march=native
on these CPUs.

Reviewed By: pengfei, anna

Differential Revision: https://reviews.llvm.org/D156963

(cherry picked from commit 2a5e3f4c6c2cdd2aab55fbfdb703ca8163351ea9)
compiler-rt/lib/builtins/cpu_model.c
llvm/lib/TargetParser/Host.cpp