[llvm] [InstCombine] Canonicalize `icmp ult (add X, C2), C` expressions (PR #95649)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 15 11:39:10 PDT 2024
================
@@ -3130,6 +3130,13 @@ Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
return new ICmpInst(ICmpInst::ICMP_EQ, Builder.CreateAnd(X, -C),
ConstantExpr::getNeg(cast<Constant>(Y)));
+ // X+C2 <u C -> (X & C) == 2C
+ // iff C == -(C2)
+ // C2 is a power of 2
+ if (Pred == ICmpInst::ICMP_ULT && C2->isPowerOf2() && (C == -(*C2)))
----------------
nikic wrote:
```suggestion
if (Pred == ICmpInst::ICMP_ULT && C2->isPowerOf2() && C == -*C2)
```
https://github.com/llvm/llvm-project/pull/95649
More information about the llvm-commits
mailing list