[llvm] [InstSimplify] Canonicalize `X uge 1` to `X ne 0` and `X sle -1` to `X slt 0` in `simplifyICmpInst` (PR #151642)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 1 06:25:03 PDT 2025
================
@@ -3774,6 +3771,17 @@ static Value *simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS,
if (Value *V = simplifyICmpOfBools(Pred, LHS, RHS, Q))
return V;
+ const APInt *C;
+ if (match(RHS, m_APIntAllowPoison(C))) {
+ if (Pred == ICmpInst::ICMP_UGE && C->isOne()) {
+ Pred = ICmpInst::ICMP_NE;
+ RHS = ConstantInt::get(RHS->getType(), 0);
+ } else if (Pred == ICmpInst::ICMP_SLE && C->isAllOnes()) {
+ Pred = ICmpInst::ICMP_SLT;
+ RHS = ConstantInt::get(RHS->getType(), 0);
+ }
+ }
----------------
nikic wrote:
Can we use getFlippedStrictnessPredicateAndConstant() to generalize this?
https://github.com/llvm/llvm-project/pull/151642
More information about the llvm-commits
mailing list