[llvm] r286259 - [RegAllocGreedy] Another fix about NewVRegs for last chance recoloring after r281783.

Wei Mi via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 8 10:19:36 PST 2016


Author: wmi
Date: Tue Nov  8 12:19:36 2016
New Revision: 286259

URL: http://llvm.org/viewvc/llvm-project?rev=286259&view=rev
Log:
[RegAllocGreedy] Another fix about NewVRegs for last chance recoloring after r281783.

About when we should move a vreg from CurrentNewVRegs to NewVRegs,
if the vreg in CurrentNewVRegs was added into RecoloringCandidate and was
evicted, it shouldn't be added to NewVRegs because its physical register
will be restored at the end of tryLastChanceRecoloring after the recoloring
failed. If the vreg in CurrentNewVRegs was not in RecoloringCandidate, i.e.
it was evicted in selectOrSplitImpl inside tryRecoloringCandidates, its
physical register will not be restored even if the recoloring failed. In
that case, we need to add the vreg to NewVRegs.

Same as r281783, the problem was seen on out-of-tree target and we didn't
have a test case that reproduce the problem with in-tree targets.

Modified:
    llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp

Modified: llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp?rev=286259&r1=286258&r2=286259&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp Tue Nov  8 12:19:36 2016
@@ -2105,9 +2105,6 @@ unsigned RAGreedy::tryLastChanceRecolori
   // Mark VirtReg as fixed, i.e., it will not be recolored pass this point in
   // this recoloring "session".
   FixedRegisters.insert(VirtReg.reg);
-  // Remember the ID of the last vreg in case the recoloring fails.
-  unsigned LastVReg =
-      TargetRegisterInfo::index2VirtReg(MRI->getNumVirtRegs() - 1);
   SmallVector<unsigned, 4> CurrentNewVRegs;
 
   Order.rewind();
@@ -2179,14 +2176,14 @@ unsigned RAGreedy::tryLastChanceRecolori
     FixedRegisters = SaveFixedRegisters;
     Matrix->unassign(VirtReg);
 
-    // When we move a register from RS_Assign to RS_Split, we do not
-    // actually do anything with it. I.e., it should not end up in NewVRegs.
-    // For the other cases, since we created new live-ranges, we need to
-    // process them.
+    // For a newly created vreg which is also in RecoloringCandidates,
+    // don't add it to NewVRegs because its physical register will be restored
+    // below. Other vregs in CurrentNewVRegs are created by calling
+    // selectOrSplit and should be added into NewVRegs.
     for (SmallVectorImpl<unsigned>::iterator Next = CurrentNewVRegs.begin(),
                                              End = CurrentNewVRegs.end();
          Next != End; ++Next) {
-      if (*Next <= LastVReg && getStage(LIS->getInterval(*Next)) == RS_Split)
+      if (RecoloringCandidates.count(&LIS->getInterval(*Next)))
         continue;
       NewVRegs.push_back(*Next);
     }




More information about the llvm-commits mailing list