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

[CodeGen] This patch fix a bug that may caused error for a self-defined target in SelectionDAG::getNode #75320

Merged
merged 1 commit into from
Dec 21, 2023

Conversation

zhou3968322
Copy link
Contributor

we need first judge N1.getNumOperands() > 0.

If Lowering Generated SDNode like.

v2i32 t20:  TargetOpNode.
i32 t21: extract_vector_elt t20  0
i32 t22: extract_vector_elt t20 1

will cause a error.

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.

@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Dec 13, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 13, 2023

@llvm/pr-subscribers-llvm-selectiondag

Author: yan zhou (zhou3968322)

Changes

we need first judge N1.getNumOperands() > 0.

If Lowering Generated SDNode like.

v2i32 t20:  TargetOpNode.
i32 t21: extract_vector_elt t20  0
i32 t22: extract_vector_elt t20 1

will cause a error.


Full diff: https://github.com/llvm/llvm-project/pull/75320.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+3-2)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 5be1892a44f6dd..5720d001d2e337 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6858,8 +6858,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     // expanding copies of large vectors from registers. This only works for
     // fixed length vectors, since we need to know the exact number of
     // elements.
-    if (N2C && N1.getOperand(0).getValueType().isFixedLengthVector() &&
-        N1.getOpcode() == ISD::CONCAT_VECTORS && N1.getNumOperands() > 0) {
+    if (N2C && N1.getNumOperands() > 0 && 
+        N1.getOperand(0).getValueType().isFixedLengthVector() &&
+        N1.getOpcode() == ISD::CONCAT_VECTORS) {
       unsigned Factor =
         N1.getOperand(0).getValueType().getVectorNumElements();
       return getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT,

@zhou3968322 zhou3968322 changed the title This patch fix a bug that may caused error for a self-defined target in SelectionDAG::getNode [CodeGen] This patch fix a bug that may caused error for a self-defined target in SelectionDAG::getNode Dec 13, 2023
Copy link

github-actions bot commented Dec 13, 2023

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

@RKSimon
Copy link
Collaborator

RKSimon commented Dec 13, 2023

This looks OK by inspection, but do you have a test case you could add as well?

@zhou3968322
Copy link
Contributor Author

zhou3968322 commented Dec 14, 2023

This looks OK by inspection, but do you have a test case you could add as well?

No, for current targets, there is no dag SDNode like this:

t20 v2i32: TargetOpNode 

It only generated a v2i32 with no input operands.
while my self-defined target still has a lot of bugs, too early to give it's example.

But I think this is only an internal change and does not affect other modules.
It can help others want to define instr like this in td,may be proper to change.

@zhou3968322 zhou3968322 force-pushed the zhou3968322-patch-1 branch 5 times, most recently from 7a9c52d to 632822c Compare December 19, 2023 02:50
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.

LGTM - cheers

first judage N1.getOpCode() == ISD::CONCAT_VECTORS  may be better.

If Lowering Generated SDNode like.

v2i32 t20:  TargetOpNode.
i32 t21: extract_vector_elt t20 0.

will cause a error.
@zhou3968322
Copy link
Contributor Author

@arsenm , no commit access, can you commit it on my behalf?

@arsenm arsenm merged commit cd09f4b into llvm:main Dec 21, 2023
4 checks passed
@zhou3968322 zhou3968322 deleted the zhou3968322-patch-1 branch December 21, 2023 13:26
@vitalybuka
Copy link
Collaborator

I guess this is broken by this patch https://lab.llvm.org/buildbot/#/builders/238/builds/7108

@topperc
Copy link
Collaborator

topperc commented Dec 21, 2023

I guess this is broken by this patch https://lab.llvm.org/buildbot/#/builders/238/builds/7108

Why do you suspect this patch?

@vitalybuka
Copy link
Collaborator

I guess this is broken by this patch https://lab.llvm.org/buildbot/#/builders/238/builds/7108

Why do you suspect this patch?

No PPC related patches
and the next in the stack is SelectionDAGBuilder
this patch is the only one related to SelectionDAG

@vitalybuka
Copy link
Collaborator

I guess this is broken by this patch https://lab.llvm.org/buildbot/#/builders/238/builds/7108

Why do you suspect this patch?

No PPC related patches and the next in the stack is SelectionDAGBuilder this patch is the only one related to SelectionDAG

That was my guess, and it was wrong. Local bisect shows f568763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants