diff --git a/lib/CodeGen/RegAllocLinearScan.cpp b/lib/CodeGen/RegAllocLinearScan.cpp index 708ecbe84af..4ff512932f8 100644 --- a/lib/CodeGen/RegAllocLinearScan.cpp +++ b/lib/CodeGen/RegAllocLinearScan.cpp @@ -87,6 +87,7 @@ namespace { // Initialize the queue to record recently-used registers. if (NumRecentlyUsedRegs > 0) RecentRegs.resize(NumRecentlyUsedRegs, 0); + RecentNext = RecentRegs.begin(); } typedef std::pair IntervalPtr; @@ -154,14 +155,16 @@ namespace { std::auto_ptr spiller_; // The queue of recently-used registers. - SmallVector RecentRegs; + SmallVector RecentRegs; + SmallVector::iterator RecentNext; // Record that we just picked this register. void recordRecentlyUsed(unsigned reg) { assert(reg != 0 && "Recently used register is NOREG!"); if (!RecentRegs.empty()) { - std::copy(RecentRegs.begin() + 1, RecentRegs.end(), RecentRegs.begin()); - RecentRegs.back() = reg; + *RecentNext++ = reg; + if (RecentNext == RecentRegs.end()) + RecentNext = RecentRegs.begin(); } }