[PATCH] D157290: [InstCombine] Fold (-a >> b) and/or (~a >> b) into (-a and/or ~a) >> b

Maksim Kita via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 7 08:26:21 PDT 2023


kitaisreal created this revision.
kitaisreal added reviewers: nikic, goldstein.w.n.
kitaisreal added projects: All, LLVM.
Herald added subscribers: StephenFan, hiraditya.
kitaisreal requested review of this revision.
Herald added a subscriber: llvm-commits.

Fold (-a >> b) and/or (~a >> b) into (-a and/or ~a) >> b https://github.com/llvm/llvm-project/issues/64304.
This optimization was already performed for unsigned arguments https://godbolt.org/z/xvvnxc4Ys, but for signed integers optimization could not be performed because of `ashr (xor %x, -1), %y --> xor (ashr %x, %y), -1` transform that was introduced in https://github.com/llvm/llvm-project/commit/485c4b552b71aff21fc27ce958c2d8ea4cebba99#diff-8c60c0e9a2dee740856faa4e8c8e5545e3236565d003f85fec4650841c976268.
In current revision I added simple implementation that inverses transformation in `tryFactorizationFolds` alive proof https://alive2.llvm.org/ce/z/kGtLvN. Maybe it make sense to create separate component that can perform such inversions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157290

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/and-or-shift.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157290.547803.patch
Type: text/x-patch
Size: 8924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230807/3d92bd97/attachment.bin>


More information about the llvm-commits mailing list