[PATCH] D124503: [InstCombine] sub(add(X,Y),umin(Y,Z)) --> add(X,usub.sat(Y,Z))

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 05:18:34 PDT 2022


spatel added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp:2042
+          if (match(Op1, m_UMin(m_Specific(Y), m_Value(Z))) ||
+              match(Op1, m_UMin(m_Value(Z), m_Specific(Y)))) {
+            Value *USub =
----------------
RKSimon wrote:
> Do we have a m_c_UMin that we can use instead?
We do have that matcher, but this would be easier if we match the umin first and then find the common operand in the add?

      // sub(add(X,Y),umin(Y,Z)) --> add(X,usub.sat(Y,Z))
      // sub(add(X,Z),umin(Y,Z)) --> add(X,usub.sat(Y,Z))
      Value *X, *Y, *Z;
      if (match(Op1, m_OneUse(m_UMin(m_Value(Y), m_Value(Z)))) &&
          (match(Op0, m_OneUse(m_c_Add(m_Specific(Y), m_Value(X)))) ||
           match(Op0, m_OneUse(m_c_Add(m_Specific(Z), m_Value(X)))))) {
        Value *USub =
            Builder.CreateIntrinsic(Intrinsic::usub_sat, I.getType(), {Y, Z});
        return BinaryOperator::CreateAdd(X, USub);
      }



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124503/new/

https://reviews.llvm.org/D124503



More information about the llvm-commits mailing list