<div dir="ltr">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 <a href="https://reviews.llvm.org/D85392">https://reviews.llvm.org/D85392</a>. They're more limited than the proposed target-independent intrinsics, but perhaps the tests from that patch would be helpful, at least.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 7, 2020 at 5:54 PM Josh Stone via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 8/7/20 7:19 AM, David Lloyd via llvm-dev wrote:<br>
> I have encountered a need for float-to-int casts that saturate to<br>
> min/max when the value is out of the range of the target type.  It<br>
> seems that there is no intrinsic to do this, currently, but on IRC it<br>
> was pointed out that a patch [1] has been proposed to implement this<br>
> functionality in exactly the way that I was looking for.<br>
> <br>
> It looks like the discussion has died out but I was hoping maybe to<br>
> kick it off again.<br>
> <br>
> [1] <a href="https://reviews.llvm.org/D54749" rel="noreferrer" target="_blank">https://reviews.llvm.org/D54749</a><br>
<br>
FWIW, Rust 1.45 just enabled saturation by default for float-to-int<br>
casts, implemented above LLVM IR -- you can find that here:<br>
<br>
<a href="https://github.com/rust-lang/rust/blob/c2d1b0d9800d922b0451921d2ce17e6ae665d5b4/src/librustc_codegen_ssa/mir/rvalue.rs#L769" rel="noreferrer" target="_blank">https://github.com/rust-lang/rust/blob/c2d1b0d9800d922b0451921d2ce17e6ae665d5b4/src/librustc_codegen_ssa/mir/rvalue.rs#L769</a><br>
<br>
And there are intrinsics for WebAssembly, at least, seen here:<br>
<br>
<a href="https://github.com/rust-lang/rust/blob/c2d1b0d9800d922b0451921d2ce17e6ae665d5b4/src/librustc_codegen_llvm/builder.rs#L656-L704" rel="noreferrer" target="_blank">https://github.com/rust-lang/rust/blob/c2d1b0d9800d922b0451921d2ce17e6ae665d5b4/src/librustc_codegen_llvm/builder.rs#L656-L704</a><br>
<br>
Target-neutral intrinsics would be nice though...<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>