[PATCH] D145341: [InstCombine] Add transform `(icmp pred (shl {nsw and/or nuw} X, Y), C)` -> `(icmp pred X, C)`

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 5 17:20:56 PST 2023


goldstein.w.n created this revision.
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.

Three new transforms:

1. `(icmp pred (shl nsw nuw X, Y), C)` [if `C <= 0`] -> `(icmp pred X, C)`
  - ugt: https://alive2.llvm.org/ce/z/K_57J_
  - sgt: https://alive2.llvm.org/ce/z/BL8u_a
  - sge: https://alive2.llvm.org/ce/z/yZZVYz
  - uge: https://alive2.llvm.org/ce/z/R4jwwJ
  - ule: https://alive2.llvm.org/ce/z/-gbmth
  - sle: https://alive2.llvm.org/ce/z/ycZVsh
  - slt: https://alive2.llvm.org/ce/z/4MzHYm
  - sle: https://alive2.llvm.org/ce/z/fgNfex
  - ult: https://alive2.llvm.org/ce/z/cXfvH5
  - eq : https://alive2.llvm.org/ce/z/sZh_Ti
  - ne : https://alive2.llvm.org/ce/z/UrqSWA
2. `(icmp eq/ne (shl {nsw|nuw} X, Y), 0)` -> `(icmp eq/ne X, 0)`
  - eq+nsw: https://alive2.llvm.org/ce/z/aSJN6D
  - eq+nuw: https://alive2.llvm.org/ce/z/r2_-br
  - ne+nuw: https://alive2.llvm.org/ce/z/RkETtu
  - ne+nsw: https://alive2.llvm.org/ce/z/8iSfW3
3. `(icmp slt (shl nsw X, Y), 0/1)` -> `(icmp pred X, 0/1)` `(icmp sgt (shl nsw X, Y), 0/-1)` -> `(icmp pred X, 0/-1)`
  - slt: https://alive2.llvm.org/ce/z/eZYRan
  - sgt: https://alive2.llvm.org/ce/z/QQeP26

    Transform 3) is really sle/slt/sge/sgt with 0, but sle/sge canonicalize to slt/sgt respectively so its implemented as such.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145341

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/test/Transforms/InstCombine/icmp-shl.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145341.502489.patch
Type: text/x-patch
Size: 5386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230306/d72a50bc/attachment-0001.bin>


More information about the llvm-commits mailing list