[PATCH] D125212: [GlobalISel] Allow destination patterns having empty outs
Abinav Puthan Purayil via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 9 01:56:41 PDT 2022
abinavpp created this revision.
abinavpp added reviewers: aemerson, arsenm, foad, Petar.Avramovic, paquette, rampitec.
Herald added a subscriber: rovka.
Herald added a project: All.
abinavpp requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
This change adds the behaviour present in SelectionDAG that allows
source SDNPHasChain patterns to be matched with destination patterns
having empty outs.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125212
Files:
llvm/test/TableGen/GlobalISelEmitter-empty-outs.td
llvm/utils/TableGen/GlobalISelEmitter.cpp
Index: llvm/utils/TableGen/GlobalISelEmitter.cpp
===================================================================
--- llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -5112,6 +5112,20 @@
return CGRegs.getSubRegIdx(SubRegInit->getDef());
}
+// This corresponds to the NodeHasChain variable in DAGISel's
+// MatcherGen::EmitResultInstructionAsOperand()
+static bool nodeHasChain(const TreePatternNode *Src,
+ const CodeGenInstruction &II,
+ const CodeGenDAGPatterns &CGP) {
+ if (Src->TreeHasProperty(SDNPHasChain, CGP)) {
+ if (II.hasCtrlDep || II.mayLoad || II.mayStore || II.canFoldAsLoad ||
+ II.hasSideEffects)
+ return true;
+ }
+
+ return false;
+}
+
Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
// Keep track of the matchers and actions to emit.
int Score = P.getPatternComplexity(CGP);
@@ -5206,15 +5220,25 @@
auto &DstI = Target.getInstruction(DstOp);
StringRef DstIName = DstI.TheDef->getName();
- if (DstI.Operands.NumDefs < Src->getExtTypes().size())
- return failedImport("Src pattern result has more defs than dst MI (" +
- to_string(Src->getExtTypes().size()) + " def(s) vs " +
- to_string(DstI.Operands.NumDefs) + " def(s))");
+ unsigned DstNumDefs = DstI.Operands.NumDefs,
+ SrcNumDefs = Src->getExtTypes().size();
+ if (DstNumDefs < SrcNumDefs) {
+ if (DstNumDefs != 0)
+ return failedImport("Src pattern result has more defs than dst MI (" +
+ to_string(SrcNumDefs) + " def(s) vs " +
+ to_string(DstNumDefs) + " def(s))");
+ if (!nodeHasChain(Src, DstI, CGP))
+ return failedImport(
+ "Src pattern result has " + to_string(SrcNumDefs) +
+ " def(s) but dst pattern result has no defs and no chain");
+ }
// The root of the match also has constraints on the register bank so that it
// matches the result instruction.
unsigned OpIdx = 0;
- for (const TypeSetByHwMode &VTy : Src->getExtTypes()) {
+ unsigned N = DstNumDefs < SrcNumDefs ? DstNumDefs : SrcNumDefs;
+ for (unsigned I = 0; I < N; ++I) {
+ const TypeSetByHwMode &VTy = Src->getExtType(I);
(void)VTy;
const auto &DstIOperand = DstI.Operands[OpIdx];
Index: llvm/test/TableGen/GlobalISelEmitter-empty-outs.td
===================================================================
--- /dev/null
+++ llvm/test/TableGen/GlobalISelEmitter-empty-outs.td
@@ -0,0 +1,26 @@
+// RUN: llvm-tblgen -gen-global-isel -warn-on-skipped-patterns -I %p/../../include -I %p/Common %s -o - < %s | FileCheck -check-prefix=GISEL %s
+
+include "llvm/Target/Target.td"
+include "GlobalISelEmitterCommon.td"
+
+// Test that we can match a src SDNPHasChain node having 1 return value with a
+// dst instruction having no return value.
+def NO_RET_ATOMIC_ADD : I<(outs), (ins GPR32Op:$src0, GPR32Op:$src1), []>;
+
+// GISEL: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_ATOMICRMW_ADD,
+// GISEL-NEXT: GIM_CheckType, /*MI*/0, /*Op*/0, /*Type*/GILLT_s32,
+// GISEL-NEXT: GIM_CheckType, /*MI*/0, /*Op*/2, /*Type*/GILLT_s32,
+// GISEL-NEXT: GIM_CheckMemorySizeEqualTo, /*MI*/0, /*MMO*/0, /*Size*/4,
+// GISEL-NEXT: // MIs[0] src0
+// GISEL-NEXT: GIM_CheckPointerToAny, /*MI*/0, /*Op*/1, /*SizeInBits*/0,
+// GISEL-NEXT: // (atomic_load_add:{ *:[i32] } iPTR:{ *:[iPTR] }:$src0, i32:{ *:[i32] }:$src1)<<P:Predicate_atomic_load_add_32>> => (NO_RET_ATOMIC_ADD GPR32:{ *:[i32] }:$src0, GPR32:{ *:[i32] }:$src1)
+// GISEL-NEXT: GIR_BuildMI, /*InsnID*/0, /*Opcode*/MyTarget::NO_RET_ATOMIC_ADD,
+// GISEL-NEXT: GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/1, // src0
+// GISEL-NEXT: GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/2, // src1
+// GISEL-NEXT: GIR_MergeMemOperands, /*InsnID*/0, /*MergeInsnID's*/0, GIU_MergeMemOperands_EndOfList,
+// GISEL-NEXT: GIR_EraseFromParent, /*InsnID*/0,
+// GISEL-NEXT: GIR_ConstrainSelectedInstOperands, /*InsnID*/0,
+def : Pat <
+ (atomic_load_add_32 iPTR:$src0, i32:$src1),
+ (NO_RET_ATOMIC_ADD GPR32:$src0, GPR32:$src1)
+>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125212.428004.patch
Type: text/x-patch
Size: 4156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220509/ef8cf52a/attachment-0001.bin>
More information about the llvm-commits
mailing list