diff --git a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h --- a/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h @@ -220,6 +220,12 @@ NumOperands(NumOperands) { } + /// Check if this mapping has the same \p OperandsMapping as another \p + /// Mapping. + bool isCompatibleMapping(const InstructionMapping &Mapping) const { + return this->OperandsMapping == Mapping.OperandsMapping; + } + /// Default constructor. /// Use this constructor to express that the mapping is invalid. InstructionMapping() = default; diff --git a/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp b/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp --- a/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp @@ -421,8 +421,19 @@ // Then the alternative mapping, if any. InstructionMappings AltMappings = getInstrAlternativeMappings(MI); - for (const InstructionMapping *AltMapping : AltMappings) - PossibleMappings.push_back(AltMapping); + for (const InstructionMapping *AltMapping : AltMappings) { + // Check that we don't already have such a mapping. + bool AlreadyExists = false; + for (const InstructionMapping *Mapping : PossibleMappings) { + if (AltMapping->isCompatibleMapping(*Mapping)) { + AlreadyExists = true; + break; + } + } + if (!AlreadyExists) { + PossibleMappings.push_back(AltMapping); + } + } #ifndef NDEBUG for (const InstructionMapping *Mapping : PossibleMappings) assert(Mapping->verify(MI) && "Mapping is invalid");