[PATCH] D157576: [DAGCombiner] Add fold for `(and/or (icmp ne/eq X,0),(icmp ne/eq X,NegPow2))`

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 20:37:03 PDT 2023


goldstein.w.n created this revision.
goldstein.w.n added reviewers: RKSimon, pengfei.
Herald added a subscriber: 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.

Add new fold for:

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

This is really an extension of the generic pattern we already support:

  `(and/or (icmp ne/eq X,C0),(icmp ne/eq X,C1))`
      -> iff `absdif(C0, C1).ispow2`
  `(icmp ne/eq (and (sub X, smin(C0, C1)), ~absdif(C0, C1)), 0)`

But negation can be faster than adding a constant, especially for
vectors where creating a zero constant can be meaningfully faster.

Proof: https://alive2.llvm.org/ce/z/edg2N2


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157576

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/icmp-pow2-diff.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157576.548864.patch
Type: text/x-patch
Size: 11379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230810/8c9d78d2/attachment.bin>


More information about the llvm-commits mailing list