[PATCH] D39960: [InstCombine] In foldSelectOpOp reuse existing selects if present

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 24 15:01:29 PST 2018


spatel added a comment.

I can see the transform that we want to make, but the way that this is coded seems wrong to me. We shouldn't have to search the block for existing operands to know if the transform is profitable.

What we should do instead is start the pattern match from a binop, so you're matching selects with a common condition operand and then binops with a common operand:

  if (match(Op0, m_Select(m_Value(Cond), m_Value(A), m_Value(B))) &&
      match(Op1, m_Select(m_Specific(Cond), m_BinOp(C), m_BinOp(D))) &&
      C->getOpcode() == D->getOpcode() && 
      C->getOperand(1) == D->getOperand(1))

This would need to have the appropriate use-checks and commutations to work properly in all cases, but I think that's better than trying to go backwards from a select.

Alternatively, couldn't / shouldn't some other pass turn multiple selects with the same condition into compare/branch/phi?


Repository:
  rL LLVM

https://reviews.llvm.org/D39960





More information about the llvm-commits mailing list