[InstCombine] Add fold for redundant sign bits count comparison
authorAlexander Shaposhnikov <ashaposhnikov@google.com>
Sat, 30 Jul 2022 09:06:37 +0000 (09:06 +0000)
committerAlexander Shaposhnikov <ashaposhnikov@google.com>
Sat, 30 Jul 2022 09:06:53 +0000 (09:06 +0000)
commit4220ef2be1c911f92b48a895fdd18e4077b322f5
tree60c727aed7a0871837e03effcef8a33028961b13
parent7912b1f8e7c845a97411cbfc176db56861cdf116
[InstCombine] Add fold for redundant sign bits count comparison

For power-of-2 C:
((X s>> ShiftC) ^ X) u< C --> (X + C) u< (C << 1)
((X s>> ShiftC) ^ X) u> (C - 1) --> (X + C) u> ((C << 1) - 1)

(https://github.com/llvm/llvm-project/issues/56479)

Test plan:
0/ ninja check-llvm check-clang + bootstrap LLVM/Clang
1/ https://alive2.llvm.org/ce/z/eEUfx3

Differential revision: https://reviews.llvm.org/D130433
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/test/Transforms/InstCombine/icmp.ll