Stabilize the avx512 target features by sayantn · Pull Request #138940 · rust-lang/rust (original) (raw)
I discovered a related mistake in LLVM. Basically
avx512f
- GCC and Intel implies onlyavx2
, LLVM also doesfma
andf16c
avx512fp16
- GCC and Intel implies onlyavx512bw
, LLVM also doesavx512dq
andavx512vl
I have filed llvm/llvm-project#136209
For avx512f
, this requirement is probably justified (see this comment). We just need to ensure that fma
and f16c
are required for avx512f
in std_detect
. I have sent a PR (rust-lang/stdarch#1781).
But we need to settle the avx512fp16
business.
This has the potential to generate invalid code (even in safe Rust, e.g https://godbolt.org/z/d3M674nY6 - here only avx512fp16
is enabled, but LLVM is generating vaddph.128
, which is not available without avx512vl
). Even if #140389 passes though, this invalid codegen will persist, as it is an LLVM issue. So essentially we have 2 options
- Don't adhere to Intel's spec. We say that
avx512fp16
impliesavx512vl
inrustc_target/target_feature.rs
, and only enable it instd_detect
whenavx512vl
is available. This is safe, with the caveat that if Intel releases a CPU withavx512fp16
, but notavx512vl
(currently none exist) Rust will just not detectavx512fp16
there. - Delay the stabilization of
avx512fp16
for now. We wait for the upstream LLVM issue to be fixed (which I believe will take a long time).
I don't think we have to delay the stabilization of any other avx512 target feature.
cc @rust-lang/lang
cc @rust-lang/wg-llvm