[InstCombine] support fold select(X|Y,X|Y,X) to X|Y
authorCongcong Cai <congcongcai0907@163.com>
Mon, 17 Apr 2023 20:06:59 +0000 (22:06 +0200)
committerCongcong Cai <congcongcai0907@163.com>
Mon, 17 Apr 2023 20:07:01 +0000 (22:07 +0200)
commitee3a260e78474b4499fc98737923ebb7df6eada8
treec36849d58af800989534bdfc36fc17022641f379
parentbeefca7239fc72967e5844540f6c820a54df9833
[InstCombine] support fold select(X|Y,X|Y,X) to X|Y

Fixed: https://github.com/llvm/llvm-project/issues/62113
Add addtional check in `visitSelectInst` to:
1. match `select(X|Y==0, X, X|Y)` and replaced with `X|Y`
2. match `select(X&Y==-1, X, X&Y)` and replaced with `X&Y`

alive proof:
https://alive2.llvm.org/ce/z/4qHmv-
https://alive2.llvm.org/ce/z/c2MBGy

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D148275
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/select_or_and.ll