[PATCH] D124763: [InstCombine] Fold A + (B & ~A) to A | B

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 05:33:06 PDT 2022


nikic created this revision.
nikic added reviewers: spatel, lebedev.ri, RKSimon.
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 folds:

- `A + (B & ~A)` --> `A | B` (https://alive2.llvm.org/ce/z/N5fWZ9)
- `A + ((A & B) ^ B)` (https://alive2.llvm.org/ce/z/so3jNz)

The reason why the second fold is necessary is that we consider this to be the canonical form if `B` is a constant. (I did check whether we can change that, but it looks like a number of folds depend on the current canonicalization, so I ended up adding both patterns here.)


https://reviews.llvm.org/D124763

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/test/Transforms/InstCombine/add.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124763.426374.patch
Type: text/x-patch
Size: 7501 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220502/324012cd/attachment.bin>


More information about the llvm-commits mailing list