target-cpu=native should also check all the target-features #54688
Labels
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Because LLVM doesn't know what
target-cpu=native
is, we currently convert this to an actual CPU family name, relying on thellvm::sys::getHostCPUName
function. So if the current CPU's family is Haswell, we converttarget-cpu=native
totarget-cpu=haswell
.As @EFanZh noticed here and here, some Intel Pentiums belong to the Haswell microarch, but they lack AVX.
Here are the flags Clang generates for
-march=native
:$ clang -E - -march=native -### -target-cpu skylake -target-feature +sse2 -target-feature +cx16 -target-feature +sahf ... -target-feature -avx512ifma -target-feature -avx512dq
Not only does it set the right
target-cpu
for optimization purposes, it actually manually enables / disables all the features available / not available on the host. This ensures no matter what the microarch is, only available features will be used.We should probably use the
llvm::sys::getHostCPUFeatures
to manually get a list of supported target features. This is what Clang does.I think this issue will supersede both #38218 and #48464. If we can fix this, we will never generate code with unavailable target features.
Reproducing these errors is pretty hard, unless you have a machine with a Haswell Intel Pentium.
I think it might be possible to reproduce this in QEMU with
-cpu Haswell,-avx
The text was updated successfully, but these errors were encountered: