[llvm] [SelectionDAG] Add m_Neg and m_Not pattern matcher and update DAGCombiner (PR #85365)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 02:59:51 PDT 2024


================
@@ -705,6 +705,20 @@ inline auto m_False() {
       },
       m_Value()};
 }
+
+/// Match a negtive as a sub(0, v)
+template <typename ValTy>
+inline BinaryOpc_match<SpecificInt_match, ValTy>
+m_Neg(const ValTy &V) {
+  return m_Sub(m_Zero(), V);
+}
+
+/// Match a Not as a xor(v, 1) or xor(1, v)
+template <typename ValTy>
+inline BinaryOpc_match<SpecificInt_match, ValTy, true>
+m_Not(const ValTy &V) {
+  return m_Xor(m_AllOnes(), V);
----------------
arsenm wrote:

This should try matching the constant in the RHS operand, as that's canonical.

The IR pattern matchers have separate _c versions for versions that try to commute the inputs 

https://github.com/llvm/llvm-project/pull/85365


More information about the llvm-commits mailing list