[llvm] [InstSimplify] Generalize simplification of icmps with monotonic operands (PR #69471)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 18 09:07:02 PDT 2023
================
@@ -3103,6 +3103,54 @@ static Value *simplifyICmpWithConstant(CmpInst::Predicate Pred, Value *LHS,
return nullptr;
}
+/// Get values V_i such that V uge V_i (Greater) or V ule V_i (!Greater).
+static void getUnsignedMonotonicValues(SmallPtrSetImpl<Value *> &Res, Value *V,
+ bool Greater, unsigned Depth = 0) {
+ if (!Res.insert(V).second)
+ return;
+
+ // Can be increased if useful.
+ if (++Depth > 1)
+ return;
+
+ Value *X, *Y;
+ if (Greater) {
+ if (match(V, m_Or(m_Value(X), m_Value(Y))) ||
+ match(V, m_Intrinsic<Intrinsic::uadd_sat>(m_Value(X), m_Value(Y)))) {
+ getUnsignedMonotonicValues(Res, X, Greater, Depth);
+ getUnsignedMonotonicValues(Res, Y, Greater, Depth);
+ }
+ } else {
+ if (match(V, m_And(m_Value(X), m_Value(Y)))) {
+ getUnsignedMonotonicValues(Res, X, Greater, Depth);
+ getUnsignedMonotonicValues(Res, Y, Greater, Depth);
+ } else if (match(V, m_URem(m_Value(X), m_Value())) ||
+ match(V, m_UDiv(m_Value(X), m_Value())) ||
+ match(V, m_LShr(m_Value(X), m_Value())) ||
+ match(V, m_Intrinsic<Intrinsic::usub_sat>(m_Value(X)))) {
+ getUnsignedMonotonicValues(Res, X, Greater, Depth);
----------------
goldsteinn wrote:
Don't need complete coverage here, but can you add TODO for some additional freebies (min/max/add+nuw/sub+nuw/mul+nuw/shl+nuw/ashr+signbit/etc...)
https://github.com/llvm/llvm-project/pull/69471
More information about the llvm-commits
mailing list