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,13 @@ // Then the alternative mapping, if any. InstructionMappings AltMappings = getInstrAlternativeMappings(MI); - for (const InstructionMapping *AltMapping : AltMappings) + for (const InstructionMapping *AltMapping : AltMappings) { + // Check that we don't already have such a mapping. + if (AltMapping->isCompatibleMapping(Mapping)) { + continue; + } PossibleMappings.push_back(AltMapping); + } #ifndef NDEBUG for (const InstructionMapping *Mapping : PossibleMappings) assert(Mapping->verify(MI) && "Mapping is invalid");