diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -7909,14 +7909,38 @@ case CmpInst::ICMP_ULE: { const APInt *C; - // LHS u<= LHS +_{nuw} C for any C - if (match(RHS, m_NUWAdd(m_Specific(LHS), m_APInt(C)))) + // LHS u<= LHS +_{nuw} V for any V + if (match(RHS, m_NUWAdd(m_Specific(LHS), m_Value()))) return true; + // RHS -_{nuw} V u<= RHS for any V + if (match(LHS, m_NUWSub(m_Specific(RHS), m_Value()))) + return true; + + // LHS u<= LHS *_{nuw} C if C is not zero + if (match(RHS, m_NUWMul(m_Specific(LHS), m_APInt(C)))) + return !C->isZero(); + + // RHS u/ C u<= RHS if C is not Zero + if (match(LHS, m_UDiv(m_Specific(RHS), m_APInt(C)))) + return !C->isZero(); + + // RHS u% C u<= RHS if C is not zero + if (match(LHS, m_URem(m_Specific(RHS), m_APInt(C)))) + return !C->isZero(); + // RHS >> V u<= RHS for any V if (match(LHS, m_LShr(m_Specific(RHS), m_Value()))) return true; + // LHS u<= LHS <<_{nuw} V for any V + if (match(RHS, m_NUWShl(m_Specific(LHS), m_Value()))) + return true; + + // RHS & V u<= RHS for any V + if (match(LHS, m_And(m_Specific(RHS), m_Value()))) + return true; + // Match A to (X +_{nuw} CA) and B to (X +_{nuw} CB) auto MatchNUWAddsToSameValue = [&](const Value *A, const Value *B, const Value *&X, diff --git a/llvm/test/Transforms/InstSimplify/implies.ll b/llvm/test/Transforms/InstSimplify/implies.ll --- a/llvm/test/Transforms/InstSimplify/implies.ll +++ b/llvm/test/Transforms/InstSimplify/implies.ll @@ -478,11 +478,7 @@ ; i +_{nuw} V i i -_{nuw} V i i / C i % C i i && C i & C