diff --git a/llvm/include/llvm/CodeGen/RegisterScavenging.h b/llvm/include/llvm/CodeGen/RegisterScavenging.h index 0eb2b2ab07f7..49d16892f87a 100644 --- a/llvm/include/llvm/CodeGen/RegisterScavenging.h +++ b/llvm/include/llvm/CodeGen/RegisterScavenging.h @@ -42,7 +42,7 @@ class RegScavenger { /// Information on scavenged registers (held in a spill slot). struct ScavengedInfo { - ScavengedInfo(int FI) : FrameIndex(FI), Reg(0), Restore(NULL) {} + ScavengedInfo(int FI = -1) : FrameIndex(FI), Reg(0), Restore(NULL) {} /// A spill slot used for scavenging a register post register allocation. int FrameIndex; @@ -130,7 +130,8 @@ public: void getScavengingFrameIndices(SmallVectorImpl &A) const { for (SmallVector::const_iterator I = Scavenged.begin(), IE = Scavenged.end(); I != IE; ++I) - A.push_back(I->FrameIndex); + if (I->FrameIndex >= 0) + A.push_back(I->FrameIndex); } /// scavengeRegister - Make a register of the specific register class diff --git a/llvm/lib/CodeGen/RegisterScavenging.cpp b/llvm/lib/CodeGen/RegisterScavenging.cpp index 4c85644e1a35..6b85cd93cf32 100644 --- a/llvm/lib/CodeGen/RegisterScavenging.cpp +++ b/llvm/lib/CodeGen/RegisterScavenging.cpp @@ -371,8 +371,11 @@ unsigned RegScavenger::scavengeRegister(const TargetRegisterClass *RC, if (Scavenged[SI].Reg == 0) break; - assert(SI < Scavenged.size() && - "Scavenger slots are live, unable to scavenge another register!"); + if (SI < Scavenged.size()) { + // We need to scavenge a register but have no spill slot, the target + // must know how to do it (if not, we'll assert below). + Scavenged.push_back(ScavengedInfo()); + } // Avoid infinite regress Scavenged[SI].Reg = SReg;