Forbid disabling SSE on x86 targets that have SSE in their "baseline" · Issue #133611 · rust-lang/rust (original) (raw)

Passing -Ctarget-feature=-sse on an x86-64 target currently produces an ugly LLVM error.
Doing the same on a x86-32 target leads to unsound floating-point behavior.

Therefore, I think we should deprecate and eventually fully forbid toggling the sse/sse2 target features on x86 targets, except for those targets that do not have these features to begin with (e.g. i586-unknown-linux-gnu).

I am implementing some machinery here that could help with that, but properly implementing this will be tricky since one can also use -Ctarget-cpu to disable these target features.

Once this is implemented, we have some options for improving the Rust ABI on these targets as well:

Here, compiler team triage decided "Current Tier 1 x86 targets require SSE-based floats at minimum". The concrete proposal above got MCP'd in rust-lang/compiler-team#808.

Open questions

How do we best implement this? It's non trivial since -Ctarget-cpu can alter the sse/sse2 feature gates, so our usual approach of just checking which target features got toggled with -Ctarget-feature does not work.

To make things worse, the way we control whether sse/sse2 is available in the "basline" is via the base.cpu field, not via the explicit list of target features, so if we want to do things "only if the baseline has SSE", that's non-trivial to implement. Maybe we should just add a bool field to the target spec that directly controls "use SSE registers for Rust ABI" or "requires SSE registers" or so?

Cc @bjorn3 @workingjubilee @Amanieu