diff --git a/lib/CodeGen/RegAllocGreedy.cpp b/lib/CodeGen/RegAllocGreedy.cpp index 1cbd5a925f2..4c130d0026b 100644 --- a/lib/CodeGen/RegAllocGreedy.cpp +++ b/lib/CodeGen/RegAllocGreedy.cpp @@ -806,7 +806,9 @@ void RAGreedy::growRegion(GlobalSplitCandidate &Cand) { if (Cand.PhysReg) addThroughConstraints(Cand.Intf, NewBlocks); else - SpillPlacer->addPrefSpill(NewBlocks); + // Provide a strong negative bias on through blocks to prevent unwanted + // liveness on loop backedges. + SpillPlacer->addPrefSpill(NewBlocks, /* Strong= */ true); AddedTo = ActiveBlocks.size(); // Perhaps iterating can enable more bundles? diff --git a/lib/CodeGen/SpillPlacement.cpp b/lib/CodeGen/SpillPlacement.cpp index 10a3c189624..6f33f5465ca 100644 --- a/lib/CodeGen/SpillPlacement.cpp +++ b/lib/CodeGen/SpillPlacement.cpp @@ -241,10 +241,12 @@ void SpillPlacement::addConstraints(ArrayRef LiveBlocks) { } /// addPrefSpill - Same as addConstraints(PrefSpill) -void SpillPlacement::addPrefSpill(ArrayRef Blocks) { +void SpillPlacement::addPrefSpill(ArrayRef Blocks, bool Strong) { for (ArrayRef::iterator I = Blocks.begin(), E = Blocks.end(); I != E; ++I) { float Freq = getBlockFrequency(*I); + if (Strong) + Freq += Freq; unsigned ib = bundles->getBundle(*I, 0); unsigned ob = bundles->getBundle(*I, 1); activate(ib); diff --git a/lib/CodeGen/SpillPlacement.h b/lib/CodeGen/SpillPlacement.h index 9d1d676c54a..fc412f817cd 100644 --- a/lib/CodeGen/SpillPlacement.h +++ b/lib/CodeGen/SpillPlacement.h @@ -107,7 +107,8 @@ public: /// Entry = Exit = PrefSpill, and ChangesValue = false. /// /// @param Blocks Array of block numbers that prefer to spill in and out. - void addPrefSpill(ArrayRef Blocks); + /// @param Strong When true, double the negative bias for these blocks. + void addPrefSpill(ArrayRef Blocks, bool Strong); /// addLinks - Add transparent blocks with the given numbers. void addLinks(ArrayRef Links);