This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Improve support for vector fp_to_sint_sat/uint_sat.
ClosedPublic

Authored by craig.topper on Sep 21 2022, 5:01 PM.

Details

Summary

The default fixed vector legalization is to unroll. The default
scalable vector legalization is to clamp in the FP domain. The
RVV vfcvt instructions have saturating behavior so we can use them
directly. The only difference is that RVV instruction turn nan into
the max value, but the _SAT intrinsics want 0.

I'm only supporting 1 step of narrowing for now. I think we can
support more steps by using VNCLIP to saturate and narrower.

The only case that needs 2 steps of widening is f16->i64 which we can
do as f16->f32->i64.

Diff Detail

Event Timeline

craig.topper created this revision.Sep 21 2022, 5:01 PM
craig.topper requested review of this revision.Sep 21 2022, 5:01 PM
HanKuanChen added inline comments.Sep 21 2022, 8:53 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1919–1923

check DstVT.getVectorNumElements() and SrcVT.getVectorNumElements() before getContainerForFixedLengthVector?

craig.topper added inline comments.Sep 21 2022, 9:13 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1919–1923

That's guaranteed by the intrinsic definition. What we need to ensure here is that the conversion from fixed to scalable is independent of the element size and only depends on the number of elements. This hasn't always been true.

frasercrmck accepted this revision.Sep 22 2022, 2:35 AM

LGTM. Thanks, this has been on my list for a long while but I've not had the bandwidth to do much upstreaming recently.

This revision is now accepted and ready to land.Sep 22 2022, 2:35 AM
This revision was landed with ongoing or failed builds.Sep 22 2022, 8:17 AM
This revision was automatically updated to reflect the committed changes.