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

Artur Bermond Torres via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 4 09:16:46 PST 2025


================
@@ -842,6 +842,16 @@ 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;
+  EXPECT_TRUE(sd_match(
+      ADD010, m_ReassociatableAdd(m_Value(A), m_Value(B), m_Deferred(A))));
+  EXPECT_TRUE(sd_match(
+      ADD010, m_ReassociatableAdd(m_Value(A), m_Value(B), m_Deferred(B))));
+  EXPECT_FALSE(sd_match(
+      ADD010, m_ReassociatableAdd(m_Value(A), m_Deferred(A), m_Deferred(A))));
+
----------------
bermondd wrote:

I just added a few more negative tests in response to another review, but they were all related to the binds done on the 2 positive test cases, e.g. to check m_Deferred(A) does not match with Op1 in the first case. I don't know if that meets what you asked for, though. Do you want me to add completely new negative test cases, alongside the current trivial one?

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


More information about the llvm-commits mailing list