[InstCombine,InstSimplify] Optimize select followed by and/or/xor
authorJuneyoung Lee <aqjune@gmail.com>
Tue, 19 Jan 2021 00:00:46 +0000 (09:00 +0900)
committerJuneyoung Lee <aqjune@gmail.com>
Tue, 19 Jan 2021 00:14:17 +0000 (09:14 +0900)
commit0441df94ad874c0c59a3785bd54a3d2f9a616fac
tree31b70b8570f8cfa9921da7a281f30e6f1f91d8c5
parent14573d44ae097969a6168fbf14cc7f796442a296
[InstCombine,InstSimplify] Optimize select followed by and/or/xor

This patch adds `A & (A && B)` -> `A && B`  (similarly for or + logical or)

Also, this patch adds `~(select C, (icmp pred X, Y), const)` -> `select C, (icmp pred' X, Y), ~const`.

Alive2 proof:
merge_and: https://alive2.llvm.org/ce/z/teMR97
merge_or: https://alive2.llvm.org/ce/z/b4yZUp
xor_and: https://alive2.llvm.org/ce/z/_-TXHi
xor_or: https://alive2.llvm.org/ce/z/2uYx_a

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D94861
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/select-safe-transforms.ll