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 << "] "