diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -2501,6 +2501,25 @@ RegAllocBase::init(getAnalysis(), getAnalysis(), getAnalysis()); + + bool HasVirtRegAlloc = false; + for (unsigned I = 0, E = MRI->getNumVirtRegs(); I != E; ++I) { + Register Reg = Register::index2VirtReg(I); + if (MRI->reg_nodbg_empty(Reg)) + continue; + const TargetRegisterClass *RC = MRI->getRegClass(Reg); + if (!RC) + continue; + if (ShouldAllocateClass(*TRI, *RC)) { + HasVirtRegAlloc = true; + break; + } + } + // Early return if there is no virtual register to be allocated to a + // physical register. + if (!HasVirtRegAlloc) + return false; + Indexes = &getAnalysis(); MBFI = &getAnalysis(); DomTree = &getAnalysis();