Use live out sets for return values instead of imp_defs, which is cleaner and faster.
[oota-llvm.git] / lib / CodeGen / BranchFolding.cpp
index 0a6bd39ee6a984febf5db4128cf64a98d68718d6..cca9f93553c60a215ac0981eb8247364ca02eff3 100644 (file)
@@ -20,7 +20,7 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
-#include "Support/STLExtras.h"
+#include "llvm/ADT/STLExtras.h"
 using namespace llvm;
 
 namespace {
@@ -96,7 +96,7 @@ static void ReplaceUsesOfBlockWith(MachineBasicBlock *BB,
 
   // If BB falls through into Old, insert an unconditional branch to New.
   MachineFunction::iterator BBSucc = BB; ++BBSucc;
-  if (&*BBSucc == Old)
+  if (BBSucc != BB->getParent()->end() && &*BBSucc == Old)
     TII.insertGoto(*BB, *New);
 
   std::vector<MachineBasicBlock*> Succs(BB->succ_begin(), BB->succ_end());