Fix a bug that David Greene found in the DAGCombiner's logic
[oota-llvm.git] / lib / CodeGen / PreAllocSplitting.cpp
index dfff87a3d7ba3970c98fb295ed96c2adf55b93f3..9e955bd69690d7b169bc56dda7af64b26d833977 100644 (file)
@@ -224,6 +224,9 @@ PreAllocSplitting::findSpillPoint(MachineBasicBlock *MBB, MachineInstr *MI,
   if (RefsInMBB.empty() && !DefMI) {
     MachineBasicBlock::iterator MII = MBB->begin();
     MachineBasicBlock::iterator EndPt = MI;
+    
+    if (MII == EndPt) return Pt;
+    
     do {
       ++MII;
       unsigned Index = LIs->getInstructionIndex(MII);
@@ -303,6 +306,9 @@ PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI,
   if (RefsInMBB.empty() && LastIdx >= EndIdx) {
     MachineBasicBlock::iterator MII = MBB->getFirstTerminator();
     MachineBasicBlock::iterator EndPt = MI;
+    
+    if (MII == EndPt) return Pt;
+    
     --MII;
     do {
       unsigned Index = LIs->getInstructionIndex(MII);
@@ -1128,7 +1134,10 @@ PreAllocSplitting::SplitRegLiveIntervals(const TargetRegisterClass **RCs,
   // by the current barrier.
   SmallVector<LiveInterval*, 8> Intervals;
   for (const TargetRegisterClass **RC = RCs; *RC; ++RC) {
-    if (TII->IgnoreRegisterClassBarriers(*RC))
+    // FIXME: If it's not safe to move any instruction that defines the barrier
+    // register class, then it means there are some special dependencies which
+    // codegen is not modelling. Ignore these barriers for now.
+    if (!TII->isSafeToMoveRegClassDefs(*RC))
       continue;
     std::vector<unsigned> &VRs = MRI->getRegClassVirtRegs(*RC);
     for (unsigned i = 0, e = VRs.size(); i != e; ++i) {