[PATCH] D109151: [InstCombine] Convert xor (ashr X, BW-1), C -> select(X >=s 0, C, ~C)

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 2 05:59:28 PDT 2021


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

The sequence of instructions `xor (ashr X, BW-1), C` (or with a truncation `xor (trunc (ashr X, BW-1)), C`) takes a value, produces all zeros or all ones and with it optionally negates a constant depending on whether the original input was positive or negative. This is the same as checking if the value is positive, and selecting between the constant and ~constant.

This is a fairly general version of the fold as part of D108049 <https://reviews.llvm.org/D108049>, which really only needs the constant to be a saturate INTMAX/INTMIN pair.


https://reviews.llvm.org/D109151

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  llvm/test/Transforms/InstCombine/truncating-saturate.ll
  llvm/test/Transforms/InstCombine/xor-ashr.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109151.370242.patch
Type: text/x-patch
Size: 14327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210902/f9f994dd/attachment.bin>


More information about the llvm-commits mailing list