[llvm] [DAG] SDPatternMatch - add a m_SpecificNeg() matcher (PR #173807)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 31 00:37:37 PST 2025


================
@@ -1299,6 +1299,32 @@ inline BinaryOpc_match<ValTy, AllOnes_match, true> m_Not(const ValTy &V) {
   return m_Xor(V, m_AllOnes());
 }
 
+struct SpecificNeg_match {
+  SDValue V;
+
+  explicit SpecificNeg_match(SDValue V) : V(V) {}
+
+  template <typename MatchContext>
+  bool match(const MatchContext &Ctx, SDValue N) {
+    if (sd_context_match(N, Ctx, m_Neg(m_Specific(V))))
+      return true;
+
+    return ISD::matchBinaryPredicate(
----------------
DaKnig wrote:

just a thought: maybe we would want to add this to m_Neg directly too? a new Neg_match class, with the rough outline:
```
  /// Match a negate as a sub(0, v)
  inline auto m_Neg<Value_match>(const Value_match &V) {
    return SpecificNeg_match(V.MatchVal);
  }
```
we could work out a better solution with less template magic but this should work hopefully, would reduce the burden of mentioning the constant bv case everywhere too

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


More information about the llvm-commits mailing list