Clean up the code a bit. Use isInstructionTriviallyDead to be more aggressive
authorChris Lattner <sabre@nondot.org>
Mon, 3 Oct 2005 23:43:43 +0000 (23:43 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 3 Oct 2005 23:43:43 +0000 (23:43 +0000)
and more correct than use_empty().  This fixes PR635 and
SimplifyCFG/2005-10-02-InvokeSimplify.ll

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23616 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp

index ba6ce17087bc61965039636ca716c6f32b72ef9f..6b5914365bb01d5e0d687b3e35cfa3fc88746ce3 100644 (file)
@@ -1284,12 +1284,16 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
                                          FalseValue, "retval", BI);
             else
               NewRetVal = TrueValue;
+            
+            DEBUG(std::cerr << "\nCHANGING BRANCH TO TWO RETURNS INTO SELECT:"
+                  << "\n  " << *BI << "Select = " << *NewRetVal
+                  << "TRUEBLOCK: " << *TrueSucc << "FALSEBLOCK: "<< *FalseSucc);
 
             new ReturnInst(NewRetVal, BI);
-            BI->getParent()->getInstList().erase(BI);
-            if (BrCond->use_empty())
-              if (Instruction *BrCondI = dyn_cast<Instruction>(BrCond))
-                BrCondI->getParent()->getInstList().erase(BrCondI);
+            BI->eraseFromParent();
+            if (Instruction *BrCondI = dyn_cast<Instruction>(BrCond))
+              if (isInstructionTriviallyDead(BrCondI))
+                BrCondI->eraseFromParent();
             return true;
           }
         }