[PATCH] D112298: [InstCombine] Generalize sadd.sat combine to compute sign bits.

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 22 02:10:00 PDT 2021


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

There is a combine in instcombine to transform a saturated add/sub into a saddsat/ssubsat, currently handling inputs which are both sign extended (https://alive2.llvm.org/ce/z/68qpTn). This can generalize to, for example ashr of at least the bitwidth (https://alive2.llvm.org/ce/z/4TFyX- and https://alive2.llvm.org/ce/z/qDWzFs for example). My understanding is that, this means it generalizes further to "the number of sign bits", needing to be enough to truncate to the size of the saturate. (An example using or for instance: https://alive2.llvm.org/ce/z/EI_h_A).

So this patch makes use of ComputeNumSignBits in matchSAddSubSat to generalize the fold to any inputs with enough sign bits known, truncating the inputs to the new size of the saturate.


https://reviews.llvm.org/D112298

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/sadd_sat.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112298.381482.patch
Type: text/x-patch
Size: 6976 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211022/07e7a760/attachment.bin>


More information about the llvm-commits mailing list