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] https://reviews.llvm.org/D54749 -- - DML • he/him
On 8/7/20 7:19 AM, David Lloyd via llvm-dev wrote:> 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] https://reviews.llvm.org/D54749FWIW, Rust 1.45 just enabled saturation by default for float-to-int casts, implemented above LLVM IR -- you can find that here: https://github.com/rust-lang/rust/blob/c2d1b0d9800d922b0451921d2ce17e6ae665d5b4/src/librustc_codegen_ssa/mir/rvalue.rs#L769 And there are intrinsics for WebAssembly, at least, seen here: https://github.com/rust-lang/rust/blob/c2d1b0d9800d922b0451921d2ce17e6ae665d5b4/src/librustc_codegen_llvm/builder.rs#L656-L704 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 https://reviews.llvm.org/D85392. They're more limited than the proposed target-independent intrinsics, but perhaps the tests from that patch would be helpful, at least. On Fri, Aug 7, 2020 at 5:54 PM Josh Stone via llvm-dev < llvm-dev at lists.llvm.org> wrote:> On 8/7/20 7:19 AM, David Lloyd via llvm-dev wrote: > > 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] https://reviews.llvm.org/D54749 > > FWIW, Rust 1.45 just enabled saturation by default for float-to-int > casts, implemented above LLVM IR -- you can find that here: > > > https://github.com/rust-lang/rust/blob/c2d1b0d9800d922b0451921d2ce17e6ae665d5b4/src/librustc_codegen_ssa/mir/rvalue.rs#L769 > > And there are intrinsics for WebAssembly, at least, seen here: > > > https://github.com/rust-lang/rust/blob/c2d1b0d9800d922b0451921d2ce17e6ae665d5b4/src/librustc_codegen_llvm/builder.rs#L656-L704 > > Target-neutral intrinsics would be nice though... > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200807/3a75c8b1/attachment-0001.html>
On Fri, Aug 7, 2020 at 9:19 AM David Lloyd <david.lloyd at redhat.com> wrote:> > 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] https://reviews.llvm.org/D54749Looks 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. -- - DML • he/him
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. ________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of David Lloyd via llvm-dev <llvm-dev at lists.llvm.org> Sent: Friday, September 4, 2020 4:42 PM To: llvm-dev at lists.llvm.org <llvm-dev at lists.llvm.org> Subject: Re: [llvm-dev] Saturating float-to-int casts On Fri, Aug 7, 2020 at 9:19 AM David Lloyd <david.lloyd at redhat.com> wrote:> > 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] https://protect2.fireeye.com/v1/url?k=0f2670d1-5186b297-0f26304a-86fc6812c361-8897797f7301e1e5&q=1&e=215b56a1-2b93-4622-a733-7123494b2246&u=https%3A%2F%2Freviews.llvm.org%2FD54749Looks 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. -- - DML • he/him _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org https://protect2.fireeye.com/v1/url?k=898c1b6b-d72cd92d-898c5bf0-86fc6812c361-8e5301a59ca3fac6&q=1&e=215b56a1-2b93-4622-a733-7123494b2246&u=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200907/e335b3e7/attachment.html>