[llvm] [InstCombine] Add combines for `(icmp eq/ne (and X, P2), (and X, -P2))` (PR #94867)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 9 11:14:56 PDT 2024
================
@@ -5570,10 +5570,35 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
Z = B;
}
- if (X) { // Build (X^Y) & Z
- Op1 = Builder.CreateXor(X, Y);
- Op1 = Builder.CreateAnd(Op1, Z);
- return new ICmpInst(Pred, Op1, Constant::getNullValue(Op1->getType()));
+ if (X) {
+ // (X&P2) == (X&-P2)
+ // -> X u< P2*2
+ // (X&P2) != (X&-P2)
+ // -> X u>= P2*2
+ // iff P2 is not INT_MIN
----------------
goldsteinn wrote:
Although we could be slightly more general in that what we really care about is `(X & HiMask) == (X & LoBitsOfHiMask)` -> `X u< RoundUpP2(LoBitsOfHiMask)`. Vice versa as well. Let me make proofs and ill update to be more general.
https://github.com/llvm/llvm-project/pull/94867
More information about the llvm-commits
mailing list