[PATCH] D140852: [Patch 4/4]: Use cannoical patterns `(A > C1 && A < C2)` and `(A & B != C)` in `isKnownNonZero`

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 2 11:22:34 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.

Both patterns where missed because they go through a level of
indirection:

1. `A > C1 && A < C2` cannonicalizes to `ICMP_ULT (A + C3, C4)`
  - Try and match this pattern explicitly in `isKnownNonNullFromDominatingCondition`

2. `A & B != C`
  - Since `cmp ne (A & B, 0)` implies `cmp ne (A, 0)` just match that as an additional generic pattern in `isKnownNonNullFromDominatingCondition`. This was already done in the final worklist loop.

The rationale is C-code like:

  int foo(int A, int B) {
      if(A % 2 == 0) {
          // A is provably odd but `isKnownNonZero(A)` will not find any
          // cmp directly acting on A. The same applies for the ICMP_ULT
          // case.
          return !!(A * B);
      }
      ...
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140852

Files:
  llvm/include/llvm/IR/InstrTypes.h
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/test/Transforms/InstCombine/icmp-binop.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140852.485877.patch
Type: text/x-patch
Size: 19834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230102/4bbb661a/attachment.bin>


More information about the llvm-commits mailing list