[llvm] [InstCombine] Add combines for `(icmp eq/ne (and X, P2), (and X, -P2))` (PR #94867)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 9 03:41:05 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
----------------
dtcxzyw wrote:
> (Not sure what the best way to check for high mask is in alive.)
A high mask is also a negated power-of-2.
See https://alive2.llvm.org/ce/z/43UGar
https://github.com/llvm/llvm-project/pull/94867
More information about the llvm-commits
mailing list