[InstCombine] Canonicalize "and, add", "or, add", "xor, add"
authorEric Gullufsen <ericgullufsen@gmail.com>
Wed, 24 Aug 2022 15:58:47 +0000 (11:58 -0400)
committerEric Gullufsen <ericgullufsen@gmail.com>
Fri, 26 Aug 2022 18:07:43 +0000 (14:07 -0400)
commitd2f110c693c88d1bb7caee4f72ebb14766f85239
tree9072e37cff75a32bc1220f32f7228fe35dbe153a
parent2f525cfb76974b7c23aeda1199dfe9d78b012d2c
[InstCombine] Canonicalize "and, add", "or, add", "xor, add"

Canonicalize
```
((x + C1) & C2) --> ((x & C2) + C1)
((x + C1) ^ C2) --> ((x ^ C2) + C1)
((x + C1) | C2) --> ((x | C2) + C1)
```
for suitable constants `C1` and `C2`.

Alive2 proofs: [[ https://alive2.llvm.org/ce/z/BqMDVZ | add, or --> or, add ]]
[[ https://alive2.llvm.org/ce/z/BhAeCl | add, xor --> xor, add ]]
[[ https://alive2.llvm.org/ce/z/jYRHEt | add, and --> and, add ]]

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D131142
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/and-xor-or.ll
llvm/test/Transforms/InstCombine/sub.ll