[PATCH] D66383: [InstCombine] Shift amount reassociation in bittest: trunc-of-lshr (PR42399)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 17 14:56:54 PDT 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: spatel, nikic, xbolva00.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.
lebedev.ri added a parent revision: D66057: [InstCombine] Shift amount reassociation in bittest: trunc-of-shl (PR42399).

Finally, the fold i was looking forward to :)

The legality check is muddy, i doubt  i've groked the full generalization,
but it handles all the cases i care about, and can come up with:
https://rise4fun.com/Alive/26j

I.e. we can perform the fold if **any** of the following is true:

- The shift amount is either zero or one less than widest bitwidth
- Either of the values being shifted has at most lowest bit set
- The value that is being shifted by `shl` (which is not truncated) should have no less leading zeros than the total shift amount;
- The value that is being shifted by `lshr` (which **is** truncated) should have no less leading zeros than the widest bit width minus total shift amount minus one

I strongly suspect there is some better generalization, but i'm not aware of it as of right now.
For now i also avoided using actual `computeKnownBits()`, but restricted it to constants.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66383

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/test/Transforms/InstCombine/shift-amount-reassociation-in-bittest-with-truncation-lshr.ll
  llvm/test/Transforms/InstCombine/shift-amount-reassociation-in-bittest-with-truncation-shl.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66383.215755.patch
Type: text/x-patch
Size: 20608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190817/cff2181c/attachment.bin>


More information about the llvm-commits mailing list