[PATCH] D125530: [InstSimplify] Fold and/or using implied conditions

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 13 03:31:01 PDT 2022


nikic created this revision.
nikic added reviewers: spatel, lebedev.ri, fhahn.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This adds two conjugated folds:

- `A | B -> B` if `A` implies `B` (https://alive2.llvm.org/ce/z/R6GU4j)
- `A & B -> A` if `A` implies `B` (https://alive2.llvm.org/ce/z/EGMqyy)

If `A` and `B` are icmps themselves, we will usually fold this through other logic already (though the tests show a couple additional cases we previously missed). However, isImpliedCond() also supports `A` being of the form `X & Y`, which allows us to handle cases like `(X & Y) | B` where `X implies B`. This addresses the regression from D125398 <https://reviews.llvm.org/D125398>.

Something that notably doesn't work yet is the `(X | Y) & B` case. This is due to an asymmetry in the isImpliedCondition() implementation that will have to be addressed separately.


https://reviews.llvm.org/D125530

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstSimplify/and-icmps-same-ops.ll
  llvm/test/Transforms/InstSimplify/and-or-implied-cond.ll
  llvm/test/Transforms/InstSimplify/or-icmps-same-ops.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125530.429183.patch
Type: text/x-patch
Size: 5125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220513/10358207/attachment.bin>


More information about the llvm-commits mailing list