[llvm] [InstCombine] fold `(icmp eq/ne (or disjoint x, C0), C1)` -> `(icmp eq/ne x, C0^C1)` (PR #87734)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 9 01:45:15 PDT 2024
================
@@ -2049,6 +2050,16 @@ Instruction *InstCombinerImpl::foldICmpOrConstant(ICmpInst &Cmp,
}
Value *OrOp0 = Or->getOperand(0), *OrOp1 = Or->getOperand(1);
+
+ // (icmp eq/ne (or disjoint x, C0), C1)
+ // -> (icmp eq/ne x, C0^C1)
+ if (Cmp.isEquality() && match(OrOp1, m_ImmConstant()) &&
+ cast<PossiblyDisjointInst>(Or)->isDisjoint()) {
+ Constant *NewC = ConstantExpr::getXor(
+ cast<Constant>(OrOp1), ConstantInt::get(OrOp1->getType(), C));
----------------
nikic wrote:
Use IRBuilder for this please, to save me the trouble of replacing it later.
https://github.com/llvm/llvm-project/pull/87734
More information about the llvm-commits
mailing list