Skip to content

Conversation

@Esan5
Copy link
Contributor

@Esan5 Esan5 commented Dec 14, 2024

fixes #118847

implements matchers for reassociatable opcodes as well as helpers for commonly used reassociatable binary matchers.

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@Esan5
Copy link
Contributor Author

Esan5 commented Dec 14, 2024

currently can't add reviewers so tagging @RKSimon and @mshockwave here

@Esan5 Esan5 force-pushed the users/esan/dag/reassociatable-matchers branch from 8e27727 to ed46b6e Compare December 15, 2024 02:27
@Esan5
Copy link
Contributor Author

Esan5 commented Dec 15, 2024

I'm having trouble recreating the failing build on windows-windows-x64. From the logs it looks like tests are faling under llvm/test/tools, but when I run these with llvm-lit llvm/test/toolseverything appears to be passing. Is there a compilation step I'm missing?

@RKSimon
Copy link
Collaborator

RKSimon commented Dec 16, 2024

It might be just the buildbot acting up - try pushing again to trigger another build

@Esan5 Esan5 force-pushed the users/esan/dag/reassociatable-matchers branch from ed46b6e to f5e70bb Compare December 16, 2024 16:29
sd_match(OR123, m_ReassociatableOr(m_Value(), m_Value(), m_Value())));
EXPECT_TRUE(sd_match(
OR0123, m_ReassociatableOr(m_Value(), m_Value(), m_Value(), m_Value())));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add some negative tests showing that it works as expected even when there are non-associative operations in the expression tree?

@Esan5
Copy link
Contributor Author

Esan5 commented Jan 27, 2025

@mshockwave could I get a review on this?

@Esan5 Esan5 force-pushed the users/esan/dag/reassociatable-matchers branch from eaecc0f to 6fddcd0 Compare February 22, 2025 19:54
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sorry I missed this) LGTM - @mshockwave any thoughts?

Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM congrats!
I suppose you don't have commit access, I'll merge this on your behalf

@mshockwave mshockwave merged commit 6b00ae6 into llvm:main Mar 21, 2025
7 checks passed
@github-actions
Copy link

@Esan5 Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 21, 2025

LLVM Buildbot has detected a new failure on builder clang-debian-cpp20 running on clang-debian-cpp20 while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/108/builds/10704

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.43.0
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': Could not resolve host: github.com
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': Could not resolve host: github.com

@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 21, 2025

LLVM Buildbot has detected a new failure on builder clangd-ubuntu-tsan running on clangd-ubuntu-clang while building llvm at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/134/builds/15528

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
git version 2.17.1
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': Could not resolve host: github.com
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': Could not resolve host: github.com

SmallVector<bool> MatchResults;
std::apply(
[&](auto &...P) {
(Matches[I].push_back(sd_context_match(Leaves[I], Ctx, P)), ...);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Esan5 I'm hitting an issue with this with m_Value() leaves that can match in multiple positions - it looks like the last leaf is binding to every m_Value() instead of sharing the matches correctly - do we need to run the matches again after reassociatableMatchHelper to ensure that each leaf is allocated and matched to a single pattern? I think technically this could still fail with m_Deferred() matches wdyt?

define i64 @test_lsb_i64(i64 %a0, i64 %a1) nounwind {
  %s0 = lshr i64 %a0, 1
  %s1 = lshr i64 %a1, 1
  %s = add i64 %s1, %s0
  %m0 = and i64 %a0, 1
  %m1 = and i64 %m0, %a1
  %res = add i64 %s, %m1
  ret i64 %res
}
    if (sd_match(N, m_ReassociatableAdd(m_Srl(m_Value(A), m_SpecificInt(1)),
                                        m_Srl(m_Value(B), m_SpecificInt(1)),
                                        m_Value(C))))
      if (sd_match(C, m_ReassociatableAnd(m_Specific(A), m_Specific(B),
                                          m_SpecificInt(1))))
        return DAG.getNode(ISD::AVGFLOORU, DL, VT, A, B);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be misunderstanding, but is the intention here for

if (sd_match(N, m_ReassociatableAdd(m_Srl(m_Value(A), m_SpecificInt(1)),
                                        m_Srl(m_Value(B), m_SpecificInt(1)),
                                        m_Value(C))))

to match

%s0 = lshr i64 %a0, 1
%s1 = lshr i64 %a1, 1
%s = add i64 %s1, %s0

The code in this helper function should prevent a given sub-pattern from being used to match more then one leaf by tracking which patterns have already been used.

Unfortunately, I don't have enough experience with LLVM to identify the intended behavior, can you clarify what this test case should do?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting m_Value(A) to match one of %s0 or %s1 and m_Value(B) to match the other - but instead both are matching to the same one.

I was really hoping to do this, but I doubt the current implementation can manage it:

if (sd_match(N, m_ReassociatableAdd(m_Srl(m_Value(A), m_SpecificInt(1)),
                                    m_Srl(m_Value(B), m_SpecificInt(1)),
                                    m_ReassociatableAnd(m_Deferred(A), m_Deferred(B), m_SpecificInt(1)))))
  return DAG.getNode(ISD::AVGFLOORU, DL, VT, A, B);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DAG] SDPatternMatch - add matchers for reassociatable binops

4 participants