[llvm] [InstCombine] Fold `icmp eq/ne (X and C), 0` when partial bits are known (PR #85863)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 14:19:26 PDT 2024
================
@@ -1771,11 +1771,14 @@ Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp,
return new ICmpInst(NewPred, X, Zero);
}
- APInt NewC2 = *C2;
KnownBits Know = computeKnownBits(And->getOperand(0), 0, And);
+ if (Know.One.intersects(*C2))
+ return replaceInstUsesWith(
+ Cmp, ConstantInt::getBool(Cmp.getType(), isICMP_NE));
----------------
goldsteinn wrote:
Is there another place we could hijack an existing knownbits calls?
This could be generalized to `!((Know.One & *C2) & ~C1).isZero()` Maybe put this in `foldICmpUsingKnownBits`?
https://github.com/llvm/llvm-project/pull/85863
More information about the llvm-commits
mailing list