[PATCH] D159059: [InstCombine] Make the `(icmp eq/ne (and X, Y), X)` canonicalization work for non-const operands

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 21:29:43 PDT 2023


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

We currently do:

  `(icmp eq/ne (and X, Y), Y)` -> `(icmp eq/ne (and ~X, Y), 0)`

if `X` is constant. We can make this more general and do it if `X` is
freely invertable (i.e say `X = ~Z`).

As well, we can also do:

  `(icmp eq/ne (and X, Y), Y)` -> `(icmp eq/ne (or X, ~Y), -1)`

If `Y` is freely invertible.

Proofs: https://alive2.llvm.org/ce/z/yeWH3E


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159059

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/test/Transforms/InstCombine/canonicalize-low-bit-mask-v2-and-icmp-eq-to-icmp-ule.ll
  llvm/test/Transforms/InstCombine/canonicalize-low-bit-mask-v2-and-icmp-ne-to-icmp-ugt.ll
  llvm/test/Transforms/InstCombine/canonicalize-low-bit-mask-v3-and-icmp-eq-to-icmp-ule.ll
  llvm/test/Transforms/InstCombine/canonicalize-low-bit-mask-v3-and-icmp-ne-to-icmp-ugt.ll
  llvm/test/Transforms/InstCombine/icmp-and-lowbit-mask.ll
  llvm/test/Transforms/InstCombine/icmp-of-and-x.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159059.554166.patch
Type: text/x-patch
Size: 9427 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230829/4a8e828c/attachment-0001.bin>


More information about the llvm-commits mailing list