[llvm] [InstSimplify] Simplify 'x u>= 1' to true when x is known non-zero (PR #145204)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 22 00:13:45 PDT 2025


================
@@ -3018,13 +3018,16 @@ static Value *simplifyICmpWithConstant(CmpPredicate Pred, Value *LHS,
   // (mul nuw/nsw X, MulC) != C --> true  (if C is not a multiple of MulC)
   // (mul nuw/nsw X, MulC) == C --> false (if C is not a multiple of MulC)
   const APInt *MulC;
-  if (IIQ.UseInstrInfo && ICmpInst::isEquality(Pred) &&
+  if (Q.IIQ.UseInstrInfo && ICmpInst::isEquality(Pred) &&
       ((match(LHS, m_NUWMul(m_Value(), m_APIntAllowPoison(MulC))) &&
         *MulC != 0 && C->urem(*MulC) != 0) ||
        (match(LHS, m_NSWMul(m_Value(), m_APIntAllowPoison(MulC))) &&
         *MulC != 0 && C->srem(*MulC) != 0)))
     return ConstantInt::get(ITy, Pred == ICmpInst::ICMP_NE);
 
+  if (Pred == ICmpInst::ICMP_UGE && C->isOne() && isKnownNonZero(LHS, Q))
+    return ConstantInt::getTrue(ITy);
----------------
nikic wrote:

I don't think this is the right way to handle this. We should instead canonicalize the predicate on entry to simplifyICmpInst() and let the existing simplification handle it.

https://github.com/llvm/llvm-project/pull/145204


More information about the llvm-commits mailing list