-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm][TableGen] Count implicit defs as well as explicit ones in the GlobalISel TableGen emitter #112673
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
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. |
@llvm/pr-subscribers-tablegen @llvm/pr-subscribers-llvm-globalisel Author: None (JL2210) Changes
Might want to use Full diff: https://github.com/llvm/llvm-project/pull/112673.diff 2 Files Affected:
diff --git a/llvm/test/TableGen/GlobalISelEmitter-implicit-defs.td b/llvm/test/TableGen/GlobalISelEmitter-implicit-defs.td
new file mode 100644
index 00000000000000..d1fb61db8c92b4
--- /dev/null
+++ b/llvm/test/TableGen/GlobalISelEmitter-implicit-defs.td
@@ -0,0 +1,13 @@
+// RUN: llvm-tblgen -gen-global-isel -warn-on-skipped-patterns -I %p/../../include -I %p/Common %s -o /dev/null 2>&1 < %s | FileCheck %s
+
+include "llvm/Target/Target.td"
+include "GlobalISelEmitterCommon.td"
+
+// CHECK-NOT: Skipped pattern: Src pattern result has 1 def(s) without the HasNoUse predicate set to true but Dst MI has no def
+// CHECK: Skipped pattern: Pattern defines a physical register
+let Uses = [B0], Defs = [B0] in
+def tst1 : I<(outs), (ins), [(set B0, (add B0, 1))]>;
+
+// CHECK: Skipped pattern: Src pattern result has 1 def(s) without the HasNoUse predicate set to true but Dst MI has no def
+let Uses = [B0] in
+def tst2 : I<(outs), (ins), [(set B0, (add B0, 1))]>;
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index c53f705a38db8f..29c64ba95ff856 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -2023,7 +2023,10 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
auto &DstI = Target.getInstruction(DstOp);
StringRef DstIName = DstI.TheDef->getName();
- unsigned DstNumDefs = DstI.Operands.NumDefs,
+ // Count both implicit and explicit defs in the dst instruction.
+ // This avoids errors importing patterns that have inherent implicit defs.
+ unsigned DstExpDefs = DstI.Operands.NumDefs,
+ DstNumDefs = DstI.ImplicitDefs.size() + DstExpDefs,
SrcNumDefs = Src.getExtTypes().size();
if (DstNumDefs < SrcNumDefs) {
if (DstNumDefs != 0)
@@ -2045,7 +2048,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
// The root of the match also has constraints on the register bank so that it
// matches the result instruction.
unsigned OpIdx = 0;
- unsigned N = std::min(DstNumDefs, SrcNumDefs);
+ unsigned N = std::min(DstExpDefs, SrcNumDefs);
for (unsigned I = 0; I < N; ++I) {
const TypeSetByHwMode &VTy = Src.getExtType(I);
|
@JL2210 I can merge this for you, please update the PR's description to the content you wish the commit message to have. Generally this means describing what the changes do and why, and removing any other content you added as questions to reviewers. |
…en emitter. NumDefs only counts the number of registers in (outs), not any implicit defs specified with Defs = [...]
more future-proof
0c3c066
to
28094f7
Compare
I think I'm happy with it now. |
@JL2210 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! |
@JL2210 After this commit I get a hard error when trying to import this pattern:
Here, Previously, this pattern was skipped with a warning:
|
@s-barannikov Sorry about that. Do you think you might be able to come up with a minimal example/testcase that fails this, so I can debug locally? I'm in the process of writing a followup to this that I think might fix the issue. |
I'll prepare a testcase |
Here is a reduced td file
|
To be clear, the issue is not urgent, I can just comment out GINodeEquiv line since the pattern wasn't imported anyway. |
@s-barannikov Thanks! I'll work on it. |
Luckily, this is what I was expecting. Printed a backtrace when this happened:
so I'm on the right track, at least |
Most of the heavy lifting was already done in importExplicitDefRenderers, so I just added an operand for the physical register defs. The logic introduced in llvm#112673 was indeed subtly broken; it was only supposed to count the physical register defs present in the pattern rather than all physical register defs. Remove importImplicitDefRenderers since it was unimplemented anyway, and I don't see a way that it could be implemented satisfactorily. Also, the name was rather misleading; it should've been called something like importPhysRegDefRenderers
NumDefs
only counts the number of registers in(outs)
, not any implicit defs specified withDefs = [...]
This causes patterns with physical register defs to fail to import here instead of later where implicit defs are rendered.
Add on
ImplicitDefs.size()
to count both and createDstExpDefs
to count only explicit defs, used later on.