You want `m_c_Or()`
On Thu, Sep 23, 2021 at 12:49 PM Zhang via llvm-dev
<llvm-dev at lists.llvm.org> wrote:>
> 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
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev