[llvm] [SDPatternMatch] Remove MatchContext (PR #218372)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 22:07:59 PDT 2026


================
@@ -4646,26 +4646,26 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
 
   // smax(a,b) - smin(a,b) --> abds(a,b)
   if ((!LegalOperations || hasOperation(ISD::ABDS, VT)) &&
-      sd_match(N0, &DAG, m_SMaxLike(m_Value(A), m_Value(B))) &&
-      sd_match(N1, &DAG, m_SMinLike(m_Specific(A), m_Specific(B))))
+      sd_match(N0, m_SMaxLike(DAG, m_Value(A), m_Value(B))) &&
+      sd_match(N1, m_SMinLike(DAG, m_Specific(A), m_Specific(B))))
----------------
lukel97 wrote:

My personal opinion is that it's safer to be explicit and pass it through the match pattern, since its easy to forget to pass the DAG in `sd_match` when its optional. E.g. see the changes in x86isellowering where we forgetting to pass it beforehand, https://github.com/llvm/llvm-project/pull/218372/changes#diff-eb2f176d67cdf1955a90e71e25d6d39910d723d4e0b8a9bf8dfa229d3a6b2c1eL56287-L56289 

FWIW I'm not 100% convinced that having computeKnownBits inside a pattern matcher is a good idea given that computeKnownBits is expensive. It seems like it would be pretty easy to nest this within a few commutative pattern matchers and end up calling it a large number of times. It seems like the type of thing that should be made explicit at the call sites.

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


More information about the llvm-commits mailing list