Index: llvm/test/TableGen/GICombinerEmitter/match-tree.td =================================================================== --- llvm/test/TableGen/GICombinerEmitter/match-tree.td +++ llvm/test/TableGen/GICombinerEmitter/match-tree.td @@ -1,6 +1,11 @@ // RUN: llvm-tblgen -I %p/../../../include -gen-global-isel-combiner \ // RUN: -combiners=MyCombinerHelper -gicombiner-stop-after-build %s \ // RUN: -o %t.inc | FileCheck %s +// +// This only checks that the code emitter does not crash. +// RUN: llvm-tblgen -I %p/../../../include -gen-global-isel-combiner \ +// RUN: -combiners=MyCombinerHelper %s \ +// RUN: -o %t.inc include "llvm/Target/Target.td" include "llvm/Target/GlobalISel/Combine.td" Index: llvm/utils/TableGen/GlobalISel/CodeExpansions.h =================================================================== --- llvm/utils/TableGen/GlobalISel/CodeExpansions.h +++ llvm/utils/TableGen/GlobalISel/CodeExpansions.h @@ -25,7 +25,8 @@ public: void declare(StringRef Name, StringRef Expansion) { bool Inserted = Expansions.try_emplace(Name, Expansion).second; - assert(Inserted && "Declared variable twice"); + // Duplicates are not inserted. The expansion refers to different operands + // but to the same virtual register. (void)Inserted; } Index: llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp =================================================================== --- llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp +++ llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp @@ -762,13 +762,14 @@ void GIMatchTreeVRegDefPartitioner::generatePartitionSelectorCode( raw_ostream &OS, StringRef Indent) const { - OS << Indent << "Partition = -1\n" - << Indent << "if (MIs.size() <= NewInstrID) MIs.resize(NewInstrID + 1);\n" + OS << Indent << "Partition = -1;\n" + << Indent << "if (MIs.size() <= " << NewInstrID << ") MIs.resize(" + << (NewInstrID + 1) << ");\n" << Indent << "MIs[" << NewInstrID << "] = nullptr;\n" - << Indent << "if (MIs[" << InstrID << "].getOperand(" << OpIdx - << ").isReg()))\n" + << Indent << "if (MIs[" << InstrID << "]->getOperand(" << OpIdx + << ").isReg())\n" << Indent << " MIs[" << NewInstrID << "] = MRI.getVRegDef(MIs[" << InstrID - << "].getOperand(" << OpIdx << ").getReg()));\n"; + << "]->getOperand(" << OpIdx << ").getReg());\n"; for (const auto &Pair : ResultToPartition) OS << Indent << "if (MIs[" << NewInstrID << "] "