[PATCH] D135380: [GlobalISel] Combine (X op Y) == X --> Y == 0

Jessica Paquette via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 6 14:08:35 PDT 2022


paquette added inline comments.


================
Comment at: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:6074-6075
+  };
+  if (!Match(/*MaybeBinOp = */ LHS, /*X = */ RHS) &&
+      !Match(/*MaybeBinOp = */ RHS, /*X = */ LHS))
+    return false;
----------------
paquette wrote:
> arsenm wrote:
> > Should there be commutative variants of the matchers like in the IR version?
> Yeah, something for G_ICMP on eq/ne would be useful. The binops already commute.
I think for a commutative matcher to make an impact here we'd need to be able to write like

```
  if (!mi_match(Dst, MRI,
                m_GICmp(m_Pred(Pred), m_Reg(X),
                        m_any_of(m_GAdd(m_SpecificReg(X), m_Reg(Y)),
                                 m_GSub(m_SpecificReg(X), m_Reg(Y)),
                                 m_GXor(m_SpecificReg(X), m_Reg(Y))))) ||
      !ICmpInst::isEquality(Pred))
    return false;
```

But I don't think that it's guaranteed that `m_Reg(X)` will be evaluated before `m_SpecificReg(X)`?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135380/new/

https://reviews.llvm.org/D135380



More information about the llvm-commits mailing list