diff --git a/llvm/include/llvm/CodeGen/SlotIndexes.h b/llvm/include/llvm/CodeGen/SlotIndexes.h --- a/llvm/include/llvm/CodeGen/SlotIndexes.h +++ b/llvm/include/llvm/CodeGen/SlotIndexes.h @@ -215,8 +215,13 @@ } /// Return the scaled distance from this index to the given one, where all - /// slots on the same instruction have zero distance. - int getInstrDistance(SlotIndex other) const { + /// slots on the same instruction have zero distance, assuming that the slot + /// indices are packed as densely as possible. This assumption is only true + /// for calculating the distance between two normally spaced instructions in + /// practice if (InstrDist / Slot_Count) - 1 instructions are inserted in + /// between them. Otherwise, this function will return a value greater than + /// the true instruction distance. + int getApproxInstrDistance(SlotIndex other) const { return (other.listEntry()->getIndex() - listEntry()->getIndex()) / Slot_Count; } 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 @@ -327,12 +327,12 @@ // are singly defined, this produces optimal coloring in the absence of // global interference and other constraints. if (!ReverseLocalAssignment) - Prio = LI.beginIndex().getInstrDistance(Indexes->getLastIndex()); + Prio = LI.beginIndex().getApproxInstrDistance(Indexes->getLastIndex()); else { // Allocating bottom up may allow many short LRGs to be assigned first // to one of the cheap registers. This could be much faster for very // large blocks on targets with many physical registers. - Prio = Indexes->getZeroIndex().getInstrDistance(LI.endIndex()); + Prio = Indexes->getZeroIndex().getApproxInstrDistance(LI.endIndex()); } } else { // Allocate global and split ranges in long->short order. Long ranges that