[PATCH] D157578: [DAGCombiner] Fold unsigned and/or of comparisons checking boundaries

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


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

The boundary comparisons are of the pattern:

- Inclusive: `(and (icmp uge/ugt Val, Lo), (icmp ule/ult Val, Hi))`
- Exclusive: `(or (icmp ule/ult Val, Lo), (icmp uge/ugt Val, Hi))`

If we are able to prove `Hi u> Lo` (or sometimes only `Hi u>= Lo`), we
can often optimize these patterns to:

  `(icmp ule/ult (sub Val, Lo), (sub Hi, Lo))`

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157578

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/test/CodeGen/AMDGPU/wave32.ll
  llvm/test/CodeGen/X86/icmp-in-unsigned-bounds.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157578.548866.patch
Type: text/x-patch
Size: 20536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230810/4edca05a/attachment.bin>


More information about the llvm-commits mailing list