-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[DAG] SDPatternMatch - add matchers for reassociatable binops #119985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DAG] SDPatternMatch - add matchers for reassociatable binops #119985
Conversation
|
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 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. |
|
currently can't add reviewers so tagging @RKSimon and @mshockwave here |
8e27727 to
ed46b6e
Compare
|
I'm having trouble recreating the failing build on |
|
It might be just the buildbot acting up - try pushing again to trigger another build |
ed46b6e to
f5e70bb
Compare
| 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()))); | ||
| } |
There was a problem hiding this comment.
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?
|
@mshockwave could I get a review on this? |
Co-authored-by: Min-Yih Hsu <[email protected]>
Co-authored-by: Min-Yih Hsu <[email protected]>
Co-authored-by: Min-Yih Hsu <[email protected]>
Co-authored-by: Min-Yih Hsu <[email protected]>
eaecc0f to
6fddcd0
Compare
RKSimon
left a comment
There was a problem hiding this 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?
There was a problem hiding this 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
|
@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 Buildbot has detected a new failure on builder 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 |
|
LLVM Buildbot has detected a new failure on builder 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 |
| SmallVector<bool> MatchResults; | ||
| std::apply( | ||
| [&](auto &...P) { | ||
| (Matches[I].push_back(sd_context_match(Leaves[I], Ctx, P)), ...); |
There was a problem hiding this comment.
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);There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
fixes #118847
implements matchers for reassociatable opcodes as well as helpers for commonly used reassociatable binary matchers.