PatternMatch Commutatively?

Hi:

I was trying to match the following pattern:


...
%8 = load i64, i64* %3, align 8
%9 = xor i64 %8, -1
...
%11 = or i64 %9, %10
...

which is roughly (~X | Y).

Given Or is commutative, I was under the assumption that trying to match (X | ~Y) would match (X | ~Y) and (~X | Y), but from testing with LLVM 11 it seems I had to match the pattern twice:


if (match(bo, m_Or(m_Value(X), m_Not(m_Value(Y))))) {
// X | (~Y)
....
} else if (match(bo, m_Or(m_Not(m_Value(X)), m_Value(Y)))) {
// (~X) | Y
....
}

and only the second code path is used.

Going through IR/PatternMatch.h , it seems that while the template BinaryOp_match has an optional argument Commutable, it defaults to false and none of m_Or, m_Xor or m_And seem to set it to true.

What am I misunderstanding here?

Zhang

You want `m_c_Or()`