[PATCH] D124119: [InstCombine] Combine instructions of type or/and where AND masks can be combined.

Biplob Mishra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 11:37:26 PDT 2022


bipmis marked an inline comment as not done.
bipmis added a comment.

I have modified and committed the tests with modifications requested. Please have a look if this looks ok. Subsequently will rebase my patch.

In the current implementation I have folded (A & B) | (C | (A & D)) ->  C | ((A & D) | (A & B)). Number of instructions have not changed as there is existing code instCombine which can do C | ((A & D) | (A & B)) -> C | (A & (D | B)). Advantage to this is less code required for implementing this and as suggested we can reduce the duplicated code and it would now look as below

  if (match(&I, m_c_Or(m_OneUse(m_And(m_Value(A), m_Value(B))), m_OneUse(m_Or(m_Value(C), m_Value(D))))))
    {
      if (match(D, m_c_And(m_Specific(A), m_Value())) ||
          match(D, m_c_And(m_Specific(B), m_Value())))
        return BinaryOperator::CreateOr(C, Builder.CreateOr(D, Builder.CreateAnd(A, B)));
      if (match(C, m_c_And(m_Specific(A), m_Value())) ||
          match(C, m_c_And(m_Specific(B), m_Value())))
        return BinaryOperator::CreateOr(Builder.CreateOr(C, Builder.CreateAnd(A, B)), D);
    }

Other option is to directly generate the reduced number of instructions (A & B) | (C | (A & D)) -> C | (A & (D | B)). In this case we will need to introduce more code. Should this be the preferred approach and would be the reason for that. Thanks.


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

https://reviews.llvm.org/D124119



More information about the llvm-commits mailing list