Index: lib/CodeGen/BranchFolding.cpp =================================================================== --- lib/CodeGen/BranchFolding.cpp +++ lib/CodeGen/BranchFolding.cpp @@ -397,6 +397,7 @@ for (unsigned int i = 1, e = TRI->getNumRegs(); i != e; i++) if (RS->isRegUsed(i, false)) NewMBB->addLiveIn(i); + NewMBB->sortUniqueLiveIns(); } } @@ -1836,6 +1837,8 @@ FBB->addLiveIn(Def); } } + TBB->sortUniqueLiveIns(); + FBB->sortUniqueLiveIns(); ++NumHoist; return true; Index: lib/CodeGen/ExecutionDepsFix.cpp =================================================================== --- lib/CodeGen/ExecutionDepsFix.cpp +++ lib/CodeGen/ExecutionDepsFix.cpp @@ -375,6 +375,7 @@ // This is the entry block. if (MBB->pred_empty()) { + MBB->sortUniqueLiveIns(); for (MachineBasicBlock::livein_iterator i = MBB->livein_begin(), e = MBB->livein_end(); i != e; ++i) { for (int rx : regIndices(*i)) { Index: lib/CodeGen/LiveVariables.cpp =================================================================== --- lib/CodeGen/LiveVariables.cpp +++ lib/CodeGen/LiveVariables.cpp @@ -557,6 +557,9 @@ } void LiveVariables::runOnBlock(MachineBasicBlock *MBB, const unsigned NumRegs) { + // Sort and Unique the LiveIns just in case. + MBB->sortUniqueLiveIns(); + // Mark live-in registers as live-in. SmallVector Defs; for (MachineBasicBlock::livein_iterator II = MBB->livein_begin(), Index: lib/CodeGen/MachineCSE.cpp =================================================================== --- lib/CodeGen/MachineCSE.cpp +++ lib/CodeGen/MachineCSE.cpp @@ -628,6 +628,8 @@ if (!MBB->isLiveIn(LiveIn)) MBB->addLiveIn(LiveIn); } + + MBB->sortUniqueLiveIns(); ++NumCrossBBCSEs; } Index: lib/CodeGen/MachineLICM.cpp =================================================================== --- lib/CodeGen/MachineLICM.cpp +++ lib/CodeGen/MachineLICM.cpp @@ -619,6 +619,7 @@ MO.setIsKill(false); } } + BB->sortUniqueLiveIns(); } } Index: lib/CodeGen/MachineRegisterInfo.cpp =================================================================== --- lib/CodeGen/MachineRegisterInfo.cpp +++ lib/CodeGen/MachineRegisterInfo.cpp @@ -391,6 +391,8 @@ // Add the register to the entry block live-in set. EntryMBB->addLiveIn(LiveIns[i].first); } + + EntryMBB->sortUniqueLiveIns(); } unsigned MachineRegisterInfo::getMaxLaneMaskForVReg(unsigned Reg) const Index: lib/CodeGen/PrologEpilogInserter.cpp =================================================================== --- lib/CodeGen/PrologEpilogInserter.cpp +++ lib/CodeGen/PrologEpilogInserter.cpp @@ -436,6 +436,9 @@ // It's killed at the spill. MBB->addLiveIn(CSI[i].getReg()); } + + for (MachineBasicBlock *MBB : Visited) + MBB->sortUniqueLiveIns(); } /// insertCSRSpillsAndRestores - Insert spill and restore code for