From b38a51e92cbdf37010a07a461d004c25cdc033f5 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Mon, 20 Mar 2017 21:58:23 +0000 Subject: [PATCH] GlobalISel: add implicit defs & uses when mutating an instruction. Otherwise a scheduler might do bad things to the code we produce. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298311 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/AArch64/GlobalISel/select-binop.mir | 4 ++-- utils/TableGen/GlobalISelEmitter.cpp | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/test/CodeGen/AArch64/GlobalISel/select-binop.mir b/test/CodeGen/AArch64/GlobalISel/select-binop.mir index a15b56fe2d6..8ae2e1b2eb7 100644 --- a/test/CodeGen/AArch64/GlobalISel/select-binop.mir +++ b/test/CodeGen/AArch64/GlobalISel/select-binop.mir @@ -224,7 +224,7 @@ registers: # CHECK: body: # CHECK: %0 = COPY %w0 # CHECK: %1 = COPY %w1 -# CHECK: %2 = SUBSWrr %0, %1 +# CHECK: %2 = SUBSWrr %0, %1, implicit-def %nzcv body: | bb.0: liveins: %w0, %w1 @@ -254,7 +254,7 @@ registers: # CHECK: body: # CHECK: %0 = COPY %x0 # CHECK: %1 = COPY %x1 -# CHECK: %2 = SUBSXrr %0, %1 +# CHECK: %2 = SUBSXrr %0, %1, implicit-def %nzcv body: | bb.0: liveins: %x0, %x1 diff --git a/utils/TableGen/GlobalISelEmitter.cpp b/utils/TableGen/GlobalISelEmitter.cpp index 596cd3cddb9..169dd32daa6 100644 --- a/utils/TableGen/GlobalISelEmitter.cpp +++ b/utils/TableGen/GlobalISelEmitter.cpp @@ -835,8 +835,25 @@ public: void emitCxxActionStmts(raw_ostream &OS, RuleMatcher &Rule, StringRef RecycleVarName) const override { if (canMutate()) { - OS << RecycleVarName << ".setDesc(TII.get(" << I->Namespace + OS << " " << RecycleVarName << ".setDesc(TII.get(" << I->Namespace << "::" << I->TheDef->getName() << "));\n"; + + if (!I->ImplicitDefs.empty() || !I->ImplicitUses.empty()) { + OS << " auto MIB = MachineInstrBuilder(MF, &" << RecycleVarName + << ");\n"; + + for (auto Def : I->ImplicitDefs) { + auto Namespace = Def->getValueAsString("Namespace"); + OS << " MIB.addDef(" << Namespace << "::" << Def->getName() + << ", RegState::Implicit);\n"; + } + for (auto Use : I->ImplicitUses) { + auto Namespace = Use->getValueAsString("Namespace"); + OS << " MIB.addUse(" << Namespace << "::" << Use->getName() + << ", RegState::Implicit);\n"; + } + } + OS << " MachineInstr &NewI = " << RecycleVarName << ";\n"; return; } -- 2.11.0