[llvm] [DAG] SDPatternMatch - Fix m_Reassociatable mismatching (PR #170061)

Artur Bermond Torres via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 4 14:20:29 PST 2025


================
@@ -842,6 +842,28 @@ TEST_F(SelectionDAGPatternMatchTest, matchReassociatableOp) {
   EXPECT_TRUE(sd_match(
       MUL, m_ReassociatableMul(m_Value(), m_Value(), m_Value(), m_Value())));
 
+  // (Op0 + Op1) + Op0 binds correctly, allowing commutation
+  SDValue ADD010 = DAG->getNode(ISD::ADD, DL, Int32VT, ADD01, Op0);
+  SDValue A, B;
----------------
bermondd wrote:

Sure! I'll implement a test for m_Value(A), m_Deferred(A), m_Value(B) in the next commit.

About m_Value(A), m_Deferred(B), m_Value(B): that actually fails (just tested locally), because as it currently is, the matching commutes the leaf nodes and not the patterns, so it will fail when trying to find a leaf match for m_Deferred(B) when B has yet to get it's value from m_Value(B), which will never be reached.

I can change this, but is it even desirable to support these kinds of patterns?

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


More information about the llvm-commits mailing list