Simplify the tracking of used physregs to a bulk bitor followed by a transitive
closure after allocating all blocks.

Add a few more test cases for -regalloc=fast.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103500 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/RegAllocFast.cpp b/lib/CodeGen/RegAllocFast.cpp
index 488f630..6bc492e 100644
--- a/lib/CodeGen/RegAllocFast.cpp
+++ b/lib/CodeGen/RegAllocFast.cpp
@@ -370,11 +370,9 @@
       if (PhysRegState[BestReg] != regDisabled)
         spillVirtReg(MBB, MI, PhysRegState[BestReg], true);
       else {
-        MF->getRegInfo().setPhysRegUsed(BestReg);
         // Make sure all aliases are disabled.
         for (const unsigned *AS = TRI->getAliasSet(BestReg);
              unsigned Alias = *AS; ++AS) {
-          MF->getRegInfo().setPhysRegUsed(Alias);
           switch (PhysRegState[Alias]) {
           case regDisabled:
             continue;
@@ -443,6 +441,7 @@
 /// defineVirtReg except the physreg is reverved instead of allocated.
 void RAFast::reservePhysReg(MachineBasicBlock &MBB, MachineInstr *MI,
                             unsigned PhysReg) {
+  UsedInInstr.set(PhysReg);
   switch (unsigned VirtReg = PhysRegState[PhysReg]) {
   case regDisabled:
     break;
@@ -460,6 +459,7 @@
   // This is a disabled register, disable all aliases.
   for (const unsigned *AS = TRI->getAliasSet(PhysReg);
        unsigned Alias = *AS; ++AS) {
+    UsedInInstr.set(Alias);
     switch (unsigned VirtReg = PhysRegState[Alias]) {
     case regDisabled:
     case regFree:
@@ -474,10 +474,8 @@
       break;
     }
     PhysRegState[Alias] = regDisabled;
-    MF->getRegInfo().setPhysRegUsed(Alias);
   }
   PhysRegState[PhysReg] = regReserved;
-  MF->getRegInfo().setPhysRegUsed(PhysReg);
 }
 
 // setPhysReg - Change MO the refer the PhysReg, considering subregs.
@@ -611,6 +609,8 @@
       killPhysReg(PhysKills[i]);
     PhysKills.clear();
 
+    MF->getRegInfo().addPhysRegsUsed(UsedInInstr);
+
     // Track registers defined by instruction - early clobbers at this point.
     UsedInInstr.reset();
     for (unsigned i = 0, e = PhysDefs.size(); i != e; ++i) {
@@ -658,6 +658,8 @@
     for (unsigned i = 0, e = PhysKills.size(); i != e; ++i)
       killPhysReg(PhysKills[i]);
     PhysKills.clear();
+
+    MF->getRegInfo().addPhysRegsUsed(UsedInInstr);
   }
 
   // Spill all physical registers holding virtual registers now.
@@ -693,6 +695,9 @@
        MBB != MBBe; ++MBB)
     AllocateBasicBlock(*MBB);
 
+  // Make sure the set of used physregs is closed under subreg operations.
+  MF->getRegInfo().closePhysRegsUsed(*TRI);
+
   StackSlotForVirtReg.clear();
   return true;
 }