[InstCombine] fold `sub + and` pattern with specific const value
authorchenglin.bi <chenglin.bi@linaro.org>
Sat, 5 Nov 2022 04:58:14 +0000 (12:58 +0800)
committerchenglin.bi <chenglin.bi@linaro.org>
Sat, 5 Nov 2022 04:58:45 +0000 (12:58 +0800)
commit670329036189040edb6c21e4fd1d98c0c979a9e2
tree239b41bbf3806016fb1fe9361f5cfd67dc9cad7a
parent6c6dff7e2c27c5a9ea9466d49f61a1edc82bc364
[InstCombine] fold `sub + and` pattern with specific const value

`C1 - ((C3 - X) & C2) --> (X & C2) + (C1 - (C2 & C3))`
when:
    (C3 - ((C2 & C3) - 1)) is pow2 &&
    ((C2 + C3) & ((C2 & C3) - 1)) == ((C2 & C3) - 1) &&
    C2 is negative pow2 || (C3 - X) is nuw

https://alive2.llvm.org/ce/z/HXQJV-

Fix: #58523

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D136582
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/sub.ll