Skip to content
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] Added m_AnyBinOp and m_c_AnyBinOp in SDPatternMatch.h #86435

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Sh0g0-1758
Copy link
Contributor

Fixes: #84940

Copy link

✅ With the latest revision this PR passed the Python code formatter.

Copy link

github-actions bot commented Mar 24, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@Sh0g0-1758 Sh0g0-1758 marked this pull request as draft March 24, 2024 13:23
@Sh0g0-1758
Copy link
Contributor Author

The rationale behind going for a separate class here is:

We would need to introduce PredFuncT in the template which would need changes in the template. This would necessitate changes in a large number of functions that use BinaryOpc_match.

llvm/include/llvm/CodeGen/SDPatternMatch.h Outdated Show resolved Hide resolved

template <typename LHS, typename RHS>
inline auto m_AnyBinOp(const LHS &L, const RHS &R) {
return AnyBinaryOp_match{[](const TargetLowering &TLI) { return true; }, L, R,
Copy link
Member

Choose a reason for hiding this comment

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

I think there is a misunderstanding here: the reason m_AnyBinOp is called "any" is because, as opposed to the existing m_BinOp who matches against a fixed opcode given by user, m_AnyBinOp will match any opcode that is TLI.isBinary/isCommutativeBinOp without any user-provided opcode to compare against with so you couldn't just return true here.
Furthermore, m_AnyBinOp(unsigned &Opc, LHS, RHS) is basically extracting the opcode that fulfills m_AnyBinOp(LHS, RHS). Therefore, I don't think PredFunc is necessary since both variants of m_AnyBinOp has to call TLI.isBinary/isCommutativeBinOp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you elaborate what you mean by:

Furthermore, m_AnyBinOp(unsigned &Opc, LHS, RHS) is basically extracting the opcode that fulfills m_AnyBinOp(LHS, RHS).

Copy link
Member

Choose a reason for hiding this comment

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

Can you elaborate what you mean by:

Furthermore, m_AnyBinOp(unsigned &Opc, LHS, RHS) is basically extracting the opcode that fulfills m_AnyBinOp(LHS, RHS).

So m_AnyBinOp(LHS, RHS) would check if the SDNode's opcode fulfills TLI.isBinOP/isCommutativeBinOp; m_AnyBinOp(unsigned &Opc, LHS, RHS) is basically doing the same thing m_AnyBinOp(LHS, RHS) does, plus returning the opcode (that has been checked) via the Opc argument (as Opc has a type of unsigned reference, making it an output argument).

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 have updated the impl. Please let me know if that is what was required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, so while I think that the m_AnyBinOp(unsigned &Opc, LHS, RHS) needs some work in the sense that I am still not returning the opcode, ie. giving Opcode the value of N->getOpcode(). But according to my testing, I don't think that isBinOp is being called at all. Any reason why?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that isBinOp is being called at all

You could attach a debugger to see why isBinOp is skipped

@@ -152,6 +152,24 @@ TEST_F(SelectionDAGPatternMatchTest, matchBinaryOp) {
sd_match(SFAdd, m_ChainedBinOp(ISD::STRICT_FADD, m_SpecificVT(Float32VT),
m_SpecificVT(Float32VT))));

EXPECT_TRUE(sd_match(And, m_AnyBinOp(ISD::AND, 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.

Have you ran this test? Because I'm a little surprised this test can be built and passed since the signature of AnyBinaryOp_match::match doesn't conform to what sd_match expects.
In case you don't know how to run a unit test, try ninja check-llvm-unit. Another way for people lacks patience like me is to explicitly build unit test via ninja UnitTests and run only the test in this file via

./unittests/CodeGen/CodeGenTests --gtest_filter='SelectionDAGPatternMatchTest.*'

(--gtest_filter comes from google test, which we use for unit testing)

@Sh0g0-1758
Copy link
Contributor Author

Ah really sorry for the delayed response. My OS crashed. Apparently there were some dependency issues with my libstdc++ that happened recently due to which I was unable to run the tests locally. I pushed the changes to get insights from you. I did a clean build of my ubuntu22.04LTS and restored my system applications. Will push the changes today.

Comment on lines +474 to +475
if ((Ctx.getTLI()->isBinOp(N->getOpcode()) ||
(Commutable && Ctx.getTLI()->isCommutativeBinOp(N->getOpcode())))) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ((Ctx.getTLI()->isBinOp(N->getOpcode()) ||
(Commutable && Ctx.getTLI()->isCommutativeBinOp(N->getOpcode())))) {
if (Ctx.getTLI()->isBinOp(N->getOpcode()) ||
(Commutable && Ctx.getTLI()->isCommutativeBinOp(N->getOpcode()))) {

Redundant paren


template <typename LHS, typename RHS>
inline auto m_AnyBinOp(const LHS &L, const RHS &R) {
return AnyBinaryOp_match{[](const TargetLowering &TLI) { return true; }, L, R,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that isBinOp is being called at all

You could attach a debugger to see why isBinOp is skipped

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 m_BinOp/m_c_BinOp variants driven by TLI.isBinOp/isCommutativeBinOp
3 participants