Avoid dereferencing off the beginning of lists.
authorEvan Cheng <evan.cheng@apple.com>
Mon, 14 Nov 2011 21:11:15 +0000 (21:11 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Mon, 14 Nov 2011 21:11:15 +0000 (21:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144569 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TwoAddressInstructionPass.cpp

index a702c6c840711c70bd11f8c79f79c91efb6d9471..6796312649186f37db3208984aa0fc24564d7b79 100644 (file)
@@ -999,10 +999,8 @@ TwoAddressInstructionPass::RescheduleMIBelowKill(MachineBasicBlock *MBB,
   }
 
   // Move debug info as well.
-  if (From != MBB->begin()) {
-    while (llvm::prior(From)->isDebugValue())
-      --From;
-  }
+  while (From != MBB->begin() && llvm::prior(From)->isDebugValue())
+    --From;
 
   // Copies following MI may have been moved as well.
   nmi = To;
@@ -1146,9 +1144,8 @@ TwoAddressInstructionPass::RescheduleKillAboveMI(MachineBasicBlock *MBB,
 
   // Move the old kill above MI, don't forget to move debug info as well.
   MachineBasicBlock::iterator InsertPos = mi;
-  if (InsertPos != MBB->begin())
-    while (llvm::prior(InsertPos)->isDebugValue())
-      --InsertPos;
+  while (InsertPos != MBB->begin() && llvm::prior(InsertPos)->isDebugValue())
+    --InsertPos;
   MachineBasicBlock::iterator From = KillMI;
   MachineBasicBlock::iterator To = llvm::next(From);
   while (llvm::prior(From)->isDebugValue())