[PATCH] D68651: [InstCombine] Signed saturation patterns

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 8 09:04:20 PDT 2019


dmgreen created this revision.
dmgreen added reviewers: spatel, nikic, lebedev.ri, efriedma.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

This adds a instcombine match for code that attempts to perform signed saturating arithmetic by casting to a higher type.  For example:
https://godbolt.org/z/9knBnP
As can be seen the unsigned cases are already matched, but signed are not. Adding them for these cases involves matching the min(max(add a b)) nodes, with proper truncs and extends.

There is some work in D68643 <https://reviews.llvm.org/D68643> to make the default lowering for these better. With that I believe that the intrinsic is a better choice than extending into a larger type (although it's obviously hard to tell for all architectures). This also helps with vectorization, especially in dsp routines that often want to use saturating arithmetic.

This also adds a m_SpecificAPInt matcher which seemed to be useful, similar to m_SpecificInt but taking an APInt for cases like this where using an APInt make sense.


https://reviews.llvm.org/D68651

Files:
  llvm/include/llvm/IR/PatternMatch.h
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/sadd_sat.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68651.223875.patch
Type: text/x-patch
Size: 15510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191008/8c44c8c3/attachment.bin>


More information about the llvm-commits mailing list