Fixed register allocator splitting a live range on a spilling variable.
[oota-llvm.git] / lib / CodeGen / MachineSink.cpp
index 7740a75e42749f55ae25c8085e7560363191e904..3837f6d888d664cbca172f1829221aeedcdf93b7 100644 (file)
@@ -149,14 +149,10 @@ MachineSinking::AllUsesDominatedByBlock(unsigned Reg,
   assert(TargetRegisterInfo::isVirtualRegister(Reg) &&
          "Only makes sense for vregs");
 
+  // Ignore debug uses because debug info doesn't affect the code.
   if (MRI->use_nodbg_empty(Reg))
     return true;
 
-  // Ignoring debug uses is necessary so debug info doesn't affect the code.
-  // This may leave a referencing dbg_value in the original block, before
-  // the definition of the vreg.  Dwarf generator handles this although the
-  // user might not get the right info at runtime.
-
   // BreakPHIEdge is true if all the uses are in the successor MBB being sunken
   // into and they are all PHI nodes. In this case, machine-sink must break
   // the critical edge first. e.g.
@@ -485,16 +481,6 @@ MachineBasicBlock *MachineSinking::FindSuccToSinkTo(MachineInstr *MI,
       for (MachineBasicBlock::succ_iterator SI = ParentBlock->succ_begin(),
            E = ParentBlock->succ_end(); SI != E; ++SI) {
        MachineBasicBlock *SuccBlock = *SI;
-       // It is not possible to sink an instruction into its own block.  This can
-       // happen with loops.
-       if (ParentBlock == SuccBlock)
-         continue;
-
-       // It's not safe to sink instructions to EH landing pad. Control flow into
-       // landing pad is implicitly defined.
-       if (SuccBlock->isLandingPad())
-         continue;
-
         bool LocalUse = false;
         if (AllUsesDominatedByBlock(Reg, SuccBlock, ParentBlock,
                                     BreakPHIEdge, LocalUse)) {
@@ -511,6 +497,17 @@ MachineBasicBlock *MachineSinking::FindSuccToSinkTo(MachineInstr *MI,
         return NULL;
     }
   }
+
+  // It is not possible to sink an instruction into its own block.  This can
+  // happen with loops.
+  if (ParentBlock == SuccToSinkTo)
+    return NULL;
+
+  // It's not safe to sink instructions to EH landing pad. Control flow into
+  // landing pad is implicitly defined.
+  if (SuccToSinkTo && SuccToSinkTo->isLandingPad())
+    return NULL;
+
   return SuccToSinkTo;
 }