Saturating float-to-int casts

I have encountered a need for float-to-int casts that saturate to
min/max when the value is out of the range of the target type. It
seems that there is no intrinsic to do this, currently, but on IRC it
was pointed out that a patch [1] has been proposed to implement this
functionality in exactly the way that I was looking for.

It looks like the discussion has died out but I was hoping maybe to
kick it off again.

[1] ⚙ D54749 Saturating float to int casts.

FWIW, Rust 1.45 just enabled saturation by default for float-to-int
casts, implemented above LLVM IR -- you can find that here:

And there are intrinsics for WebAssembly, at least, seen here:

Target-neutral intrinsics would be nice though...

I would be happy to be able to replace the WebAssembly-specific saturating float-to-int intrinsics with target-independent versions if they were available. I have a patch up implementing constant folding for the WebAssembly intrinsics at They’re more limited than the proposed target-independent intrinsics, but perhaps the tests from that patch would be helpful, at least.

Looks like a little more activity has happened, and the patch was
rebased, but some unit tests are currently failing (I have no idea how
normal that is but I'm assuming it's a problem - at least the failures
seem related, on the surface anyway). Seems like the failures are
related to applying these operations to vectors.

I’m the one who has been working on this patch.

I have noticed the test failures, but I cannot reproduce those when I build and test locally, so I haven’t actively tried to do anything about them. I don’t put much stock in the pre-land tests, they tend to fail in odd ways.