[PATCH] D32725: [InstCombine] Apply deMorgan to (and/or (not cmp1), cmp2) when cmp1 has multiple uses, but cmp2 has a single use

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 08:56:33 PDT 2017


spatel added a comment.

In https://reviews.llvm.org/D32725#743679, @efriedma wrote:

> I'm not quite sure about this the way it's written.  This doesn't reduce the total number of instructions on its own, and it seems like an overly complicated pattern.  You could approach this from a different angle: fold xor(icmp(pred, x, y)) to (icmp (!pred, x, y)) even if the inner icmp has multiple uses.  Or maybe this is okay as-is; my intuition about what's right here isn't strong.


I think that folding to icmp with inverse predicate (regardless of number of uses) is the right thing to do because it eliminates a dependency between icmp and xor (not). Plus, we have tons of folds/analysis for icmp.

In other words, we should get rid of the m_OneUse here:

  // xor (cmp A, B), true = not (cmp A, B) = !cmp A, B
  ICmpInst::Predicate Pred;
  if (match(Op0, m_OneUse(m_Cmp(Pred, m_Value(), m_Value()))) &&

There was at least one missing fold exposed by this change in a regression test when I checked it previously.


https://reviews.llvm.org/D32725





More information about the llvm-commits mailing list