Skip to content

Commit 8f6d491

Browse files
authored
[llvm][TableGen] Count implicit defs as well as explicit ones in the GlobalISel TableGen emitter (#112673)
`NumDefs` only counts the number of registers in `(outs)`, not any implicit defs specified with `Defs = [...]` 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 create `DstExpDefs` to count only explicit defs, used later on.
1 parent 4e01690 commit 8f6d491

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// 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 --implicit-check-not="Skipped pattern"
2+
3+
include "llvm/Target/Target.td"
4+
include "GlobalISelEmitterCommon.td"
5+
6+
// CHECK: Skipped pattern: Pattern defines a physical register
7+
let Uses = [B0], Defs = [B0] in
8+
def tst1 : I<(outs), (ins), [(set B0, (add B0, 1))]>;
9+
10+
// CHECK: Skipped pattern: Src pattern result has 1 def(s) without the HasNoUse predicate set to true but Dst MI has no def
11+
let Uses = [B0] in
12+
def tst2 : I<(outs), (ins), [(set B0, (add B0, 1))]>;

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,10 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
20232023
auto &DstI = Target.getInstruction(DstOp);
20242024
StringRef DstIName = DstI.TheDef->getName();
20252025

2026-
unsigned DstNumDefs = DstI.Operands.NumDefs,
2026+
// Count both implicit and explicit defs in the dst instruction.
2027+
// This avoids errors importing patterns that have inherent implicit defs.
2028+
unsigned DstExpDefs = DstI.Operands.NumDefs,
2029+
DstNumDefs = DstI.ImplicitDefs.size() + DstExpDefs,
20272030
SrcNumDefs = Src.getExtTypes().size();
20282031
if (DstNumDefs < SrcNumDefs) {
20292032
if (DstNumDefs != 0)
@@ -2045,7 +2048,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
20452048
// The root of the match also has constraints on the register bank so that it
20462049
// matches the result instruction.
20472050
unsigned OpIdx = 0;
2048-
unsigned N = std::min(DstNumDefs, SrcNumDefs);
2051+
unsigned N = std::min(DstExpDefs, SrcNumDefs);
20492052
for (unsigned I = 0; I < N; ++I) {
20502053
const TypeSetByHwMode &VTy = Src.getExtType(I);
20512054

0 commit comments

Comments
 (0)