Skip to content

[DAG] SDPatternMatch - m_Reassociatable mismatches #169645

@RKSimon

Description

@RKSimon

Noticed while working on #169644

If we attempt to match a m_ReassociatableAdd pattern containing both the m_Value and m_Deferred for a given SDValue, the matcher gets corrupted and fails to match the correct SDValue pairs

foldAddToAvg:

  if ((!LegalOperations || hasOperation(ISD::AVGFLOORU, VT)) &&
      (sd_match(N,
                m_Add(m_And(m_Value(A), m_Value(B)),
                      m_Srl(m_Xor(m_Deferred(A), m_Deferred(B)), m_One()))) ||
       sd_match(N, m_ReassociatableAdd(
                       m_Srl(m_Value(A), m_One()), m_Srl(m_Value(B), m_One()),
                       m_ReassociatableAnd(m_Deferred(A), m_Deferred(B),
                                           m_One()))))) {
    return DAG.getNode(ISD::AVGFLOORU, DL, VT, A, B);
  }

in this case we end up with the same SDValue being matched for A and B.

Hopefully this is just an evaluation ordering issue, but there might be something else going on.

Good first issue for someone who likes template programming!

Metadata

Metadata

Assignees

Labels

good first issuehttps://github.com/llvm/llvm-project/contributellvm:SelectionDAGSelectionDAGISel as well

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions