Add an intrinsic that takes 2 integers and perform unsigned saturation addition on them.
This is a part of implementing fixed point arithmetic in clang where some of the more complex operations will be implemented as intrinsics.
Paths
| Differential D53340
[Intrinsic] Unigned Saturation Addition Intrinsic ClosedPublic Authored by leonardchan on Oct 16 2018, 2:09 PM.
Details Summary Add an intrinsic that takes 2 integers and perform unsigned saturation addition on them. This is a part of implementing fixed point arithmetic in clang where some of the more complex operations will be implemented as intrinsics.
Diff Detail
Event TimelineComment Actions Is this intrinsic really needed for the fixed point support? Maybe I've missed something in the discussions about support for unsigned fixed point types, but in our implementation the unsigned types are using the positive range of the signed type, such as [0, SIGNED_MAX]. So we keep the sign bit zero for the unsigned fixed point types. Are you planning for something different here? In our implementation we lower addition of two saturated unsigned fixed point types to sadd.sat (if the input values are in the range [0, SIGNED_MAX] the result will be in the range [0, SIGNED_MAX] as well). So we haven't really found a need for implementing uadd.sat. Comment Actions LGTM!
Our implementation is one without the padding bit on unsigned types, so we don't need a uadd.sat. The same applies to fixumul (which we also don't have). As you say, unsigned operations can be implemented in terms of the signed ones in that kind of implementation.
leonardchan marked an inline comment as done. Comment Actions
By default we have unsigned fixed point types in clang to use the entire length of the int, so it ranges from [0, UNSIGNED_MAX]. In this case I think it would be useful to have an unsigned version as well. This could also be used for regular unsigned integers that do not have a padding bit, and I believe @craig.topper was interested in this so they could be replaced with target specific calls to x86 intrinsics like PADDUSB and PADDUSW. Comment Actions
Ok, I see. That explains the need for it. I haven't really reviewed the test case in detail (I'm not that familiar with the X86 vector instructions), but this LGTM. This revision is now accepted and ready to land.Oct 22 2018, 3:36 PM Closed by commit rL344971: [Intrinsic] Unigned Saturation Addition Intrinsic (authored by leonardchan). · Explain WhyOct 22 2018, 4:11 PM This revision was automatically updated to reflect the committed changes. spatel mentioned this in D96904: [IR] restrict vector reduction intrinsic types.Feb 19 2021, 9:23 AM
Revision Contents
Diff 170521 llvm/trunk/include/llvm/CodeGen/ISDOpcodes.h
llvm/trunk/include/llvm/CodeGen/TargetLowering.h
llvm/trunk/include/llvm/IR/Intrinsics.td
llvm/trunk/include/llvm/Target/TargetSelectionDAG.td
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/trunk/lib/CodeGen/TargetLoweringBase.cpp
llvm/trunk/lib/IR/Verifier.cpp
llvm/trunk/test/CodeGen/X86/uadd_sat.ll
|