Skip to content

Commit 101b900

Browse files
committed
fix the bug
1 parent 903f279 commit 101b900

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

llvm/test/TableGen/GlobalISelEmitter/dead-def.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ def I2 : I<(outs GPR32:$other_name, GPR32:$same_name), (ins GPR32:$rs), []>;
1212
def : Pat<(abs i32:$x), (I1 (I2 $x))>;
1313

1414
// CHECK-LABEL: // (abs:{ *:[i32] } i32:{ *:[i32] }:$x) => (I1:{ *:[i32] } (I2:{ *:[i32] }:{ *:[i32] } ?:{ *:[i32] }:$x))
15+
// CHECK-NEXT: GIR_MakeTempReg, /*TempRegID*/1, /*TypeID*/GILLT_s32,
1516
// CHECK-NEXT: GIR_MakeTempReg, /*TempRegID*/0, /*TypeID*/GILLT_s32,
1617
// CHECK-NEXT: GIR_BuildMI, /*InsnID*/1, /*Opcode*/GIMT_Encode2(MyTarget::I2),
1718
// CHECK-NEXT: GIR_AddTempRegister, /*InsnID*/1, /*TempRegID*/0, /*TempRegFlags*/GIMT_Encode2(RegState::Define),
18-
// CHECK-NEXT: GIR_Copy, /*NewInsnID*/1, /*OldInsnID*/0, /*OpIdx*/0, // DstI[same_name]
19+
// CHECK-NEXT: GIR_AddTempRegister, /*InsnID*/1, /*TempRegID*/1, /*TempRegFlags*/GIMT_Encode2(RegState::Define|RegState::Dead),
1920
// CHECK-NEXT: GIR_Copy, /*NewInsnID*/1, /*OldInsnID*/0, /*OpIdx*/1, // x
2021
// CHECK-NEXT: GIR_ConstrainSelectedInstOperands, /*InsnID*/1,
2122
// CHECK-NEXT: GIR_BuildRootMI, /*Opcode*/GIMT_Encode2(MyTarget::I1),

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,10 @@ class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter {
404404
createInstructionRenderer(action_iterator InsertPt, RuleMatcher &M,
405405
const TreePatternNode &Dst) const;
406406

407-
Expected<action_iterator> importExplicitDefRenderers(
408-
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
409-
const TreePatternNode &Dst, unsigned Start = 0) const;
407+
Expected<action_iterator>
408+
importExplicitDefRenderers(action_iterator InsertPt, RuleMatcher &M,
409+
BuildMIAction &DstMIBuilder,
410+
const TreePatternNode &Dst, bool IsRoot) const;
410411

411412
Expected<action_iterator>
412413
importExplicitUseRenderers(action_iterator InsertPt, RuleMatcher &M,
@@ -1375,7 +1376,8 @@ Expected<BuildMIAction &> GlobalISelEmitter::createAndImportInstructionRenderer(
13751376
CopyToPhysRegMIBuilder.addRenderer<CopyPhysRegRenderer>(PhysInput.first);
13761377
}
13771378

1378-
if (auto Error = importExplicitDefRenderers(InsertPt, M, DstMIBuilder, Dst)
1379+
if (auto Error = importExplicitDefRenderers(InsertPt, M, DstMIBuilder, Dst,
1380+
/*IsRoot=*/true)
13791381
.takeError())
13801382
return std::move(Error);
13811383

@@ -1404,8 +1406,8 @@ GlobalISelEmitter::createAndImportSubInstructionRenderer(
14041406
DstMIBuilder.addRenderer<TempRegRenderer>(TempRegID, true);
14051407

14061408
// Handle additional (ignored) results.
1407-
InsertPtOrError = importExplicitDefRenderers(std::prev(*InsertPtOrError), M,
1408-
DstMIBuilder, Dst, /*Start=*/1);
1409+
InsertPtOrError = importExplicitDefRenderers(
1410+
std::prev(*InsertPtOrError), M, DstMIBuilder, Dst, /*IsRoot=*/false);
14091411
if (auto Error = InsertPtOrError.takeError())
14101412
return std::move(Error);
14111413

@@ -1446,16 +1448,16 @@ GlobalISelEmitter::createInstructionRenderer(action_iterator InsertPt,
14461448

14471449
Expected<action_iterator> GlobalISelEmitter::importExplicitDefRenderers(
14481450
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
1449-
const TreePatternNode &Dst, unsigned Start) const {
1451+
const TreePatternNode &Dst, bool IsRoot) const {
14501452
const CodeGenInstruction *DstI = DstMIBuilder.getCGI();
14511453

14521454
// Process explicit defs. The caller may have already handled the first def.
1453-
for (unsigned I = Start, E = DstI->Operands.NumDefs; I != E; ++I) {
1455+
for (unsigned I = IsRoot ? 0 : 1, E = DstI->Operands.NumDefs; I != E; ++I) {
14541456
const CGIOperandList::OperandInfo &OpInfo = DstI->Operands[I];
14551457
std::string OpName = getMangledRootDefName(OpInfo.Name);
14561458

14571459
// If the def is used in the source DAG, forward it.
1458-
if (M.hasOperand(OpName)) {
1460+
if (IsRoot && M.hasOperand(OpName)) {
14591461
// CopyRenderer saves a StringRef, so cannot pass OpName itself -
14601462
// let's use a string with an appropriate lifetime.
14611463
StringRef PermanentRef = M.getOperandMatcher(OpName).getSymbolicName();

0 commit comments

Comments
 (0)