[PATCH] D31680: [InstCombine] Use commutable and/or/xor matchers to simplify some code

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 16:18:59 PDT 2017


spatel added a comment.

This is the minimum improvement, but we can do better. :)

1. It's unlikely that we actually have tests for all of the commuted variants. I noticed that when I made a change to the operand complexity values a few months ago. Adding the missing cases would be a nice improvement.
2. The nullptr initialization for the captured Values isn't necessary.
3. We don't have an m_c_Add, but we probably should for situations like these.
4. Even if we had an m_c_Add, I don't think we'd be able to use it with m_Specific in this case because we need the generic half to capture first. I haven't actually tested that, so it's worth an experiment.
5. If #3 is not an option, then we can do one of these (and there's no consensus in existing code about which is best):
  1. Glom the match statements together with a big '||'. (At least get rid of the duplicated code within each 'if' clause)
  2. Test if the xor is on the right and std::swap the add operands.
  3. Use normal value capture and check for the operand equality after that:

     

  Value *A, *B, *C, *D;
  if (match(&I, m_c_Add(m_Xor(m_Value(A), m_Value(B)),
                        m_And(m_Value(C), m_Value(D)))) &&
      ((A == C && B == D) || (A == D && B == C)))
    return BinaryOperator::CreateOr(A, B);



https://reviews.llvm.org/D31680





More information about the llvm-commits mailing list