Minor optimizations. DenseMap::begin() is surprisingly slow on an empty map.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Mon, 17 May 2010 15:30:37 +0000 (15:30 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Mon, 17 May 2010 15:30:37 +0000 (15:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103940 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/RegAllocFast.cpp

index 70c1c1e3e68db1f6eacb328322ee828b32673f4c..ea3fa61c89099580322576a2b86120c7d7183052 100644 (file)
@@ -267,6 +267,7 @@ void RAFast::spillVirtReg(MachineBasicBlock::iterator MI,
 
 /// spillAll - Spill all dirty virtregs without killing them.
 void RAFast::spillAll(MachineInstr *MI) {
+  if (LiveVirtRegs.empty()) return;
   isBulkSpilling = true;
   for (LiveRegMap::iterator i = LiveVirtRegs.begin(),
        e = LiveVirtRegs.end(); i != e; ++i)
@@ -471,17 +472,15 @@ void RAFast::allocVirtReg(MachineInstr *MI, LiveRegEntry &LRE, unsigned Hint) {
   unsigned BestReg = 0, BestCost = spillImpossible;
   for (TargetRegisterClass::iterator I = AOB; I != AOE; ++I) {
     unsigned Cost = calcSpillCost(*I);
-    if (Cost < BestCost) {
-      BestReg = *I;
-      BestCost = Cost;
-      if (Cost == 0) break;
-    }
+    // Cost is 0 when all aliases are already disabled.
+    if (Cost == 0)
+      return assignVirtToPhysReg(LRE, *I);
+    if (Cost < BestCost)
+      BestReg = *I, BestCost = Cost;
   }
 
   if (BestReg) {
-    // BestCost is 0 when all aliases are already disabled.
-    if (BestCost)
-      definePhysReg(MI, BestReg, regFree);
+    definePhysReg(MI, BestReg, regFree);
     return assignVirtToPhysReg(LRE, BestReg);
   }