[InstCombine] Optimise shift+and+boolean conversion pattern to simple comparison
authorchenglin.bi <chenglin.bi@cixcomputing.com>
Thu, 23 Jun 2022 13:47:45 +0000 (21:47 +0800)
committerchenglin.bi <chenglin.bi@cixcomputing.com>
Thu, 23 Jun 2022 13:53:07 +0000 (21:53 +0800)
commit30e49a3794726fd9d0ae60d34880f15e64a9fb3f
tree6b09b00cd8ede7ff84ad65bc2439d3a34aa13f5f
parent6b187fdf3bb409061b6a235487517f478b09afed
[InstCombine] Optimise shift+and+boolean conversion pattern to simple comparison

if (`C1` is pow2) & (`(C2 & ~(C1-1)) + C1)` is pow2):
    ((C1 << X) & C2) == 0 -> X >= (Log2(C2+C1) - Log2(C1));
https://alive2.llvm.org/ce/z/EJAl1R
    ((C1 << X) & C2) != 0 -> X  < (Log2(C2+C1) - Log2(C1));
https://alive2.llvm.org/ce/z/3bVRVz

And remove dead code.

Fix: https://github.com/llvm/llvm-project/issues/56124

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D126591
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-and-shift.ll