Be more conservative when forming compact regions.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 3 Aug 2011 23:09:38 +0000 (23:09 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 3 Aug 2011 23:09:38 +0000 (23:09 +0000)
Apply twice the negative bias on transparent blocks when computing the
compact regions. This excludes loop backedges from the region when only
one of the loop blocks uses the register.

Previously, we would include the backedge in the region if the loop
preheader and the loop latch both used the register, but the loop header
didn't.

When both the header and latch blocks use the register, we still keep it
live on the backedge.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136832 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/RegAllocGreedy.cpp
lib/CodeGen/SpillPlacement.cpp
lib/CodeGen/SpillPlacement.h

index 1cbd5a925f2cb5aaae2a22b2273ce6dc243b34e1..4c130d0026beca42ff28a1d074dd2b15bb6fde11 100644 (file)
@@ -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?
index 10a3c189624e0360d06db395124652a0f2356b5f..6f33f5465ca2b427cf19d0079673f7674b4f8996 100644 (file)
@@ -241,10 +241,12 @@ void SpillPlacement::addConstraints(ArrayRef<BlockConstraint> LiveBlocks) {
 }
 
 /// addPrefSpill - Same as addConstraints(PrefSpill)
-void SpillPlacement::addPrefSpill(ArrayRef<unsigned> Blocks) {
+void SpillPlacement::addPrefSpill(ArrayRef<unsigned> Blocks, bool Strong) {
   for (ArrayRef<unsigned>::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);
index 9d1d676c54aeae52bc454e9dd65fd08b660e437c..fc412f817cdb490545129c4bfd9710558a4b0fd4 100644 (file)
@@ -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<unsigned> Blocks);
+  /// @param Strong When true, double the negative bias for these blocks.
+  void addPrefSpill(ArrayRef<unsigned> Blocks, bool Strong);
 
   /// addLinks - Add transparent blocks with the given numbers.
   void addLinks(ArrayRef<unsigned> Links);