[llvm-commits] [llvm] r77512 - in /llvm/trunk: lib/Transforms/Scalar/SimplifyLibCalls.cpp test/Transforms/SimplifyLibCalls/2009-07-29-Exit2.ll

Daniel Dunbar daniel at zuster.org
Wed Jul 29 15:00:43 PDT 2009


Author: ddunbar
Date: Wed Jul 29 17:00:43 2009
New Revision: 77512

URL: http://llvm.org/viewvc/llvm-project?rev=77512&view=rev
Log:
Fix PR4645 which was fallout from the fix for PR4641.
 - Call RAUW to delete all instructions (this is a patch from Nick Lewycky).

Added:
    llvm/trunk/test/Transforms/SimplifyLibCalls/2009-07-29-Exit2.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=77512&r1=77511&r2=77512&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Wed Jul 29 17:00:43 2009
@@ -29,6 +29,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -518,18 +519,24 @@
       return 0;
 
     TerminatorInst *OldTI = CI->getParent()->getTerminator();
-    
+
     // Drop all successor phi node entries.
     for (unsigned i = 0, e = OldTI->getNumSuccessors(); i != e; ++i)
       OldTI->getSuccessor(i)->removePredecessor(CI->getParent());
-    
-    // Split the basic block after the call to exit.
-    BasicBlock::iterator FirstDead = CI; ++FirstDead;
-    CI->getParent()->splitBasicBlock(FirstDead);
-    B.SetInsertPoint(B.GetInsertBlock());
 
-    // Remove the branch that splitBB created and insert a return instead.
-    CI->getParent()->getTerminator()->eraseFromParent();
+    // Remove all instructions after the exit.
+    BasicBlock::iterator Dead = CI, E = OldTI; ++Dead;
+    while (Dead != E) {
+      BasicBlock::iterator Next = next(Dead);
+      if (Dead->getType() != Type::VoidTy)
+        Dead->replaceAllUsesWith(UndefValue::get(Dead->getType()));
+      Dead->eraseFromParent();
+      Dead = Next;
+    }
+
+    // Insert a return instruction.
+    OldTI->eraseFromParent();
+    B.SetInsertPoint(B.GetInsertBlock());
     B.CreateRet(CI->getOperand(1));
 
     return CI;

Added: llvm/trunk/test/Transforms/SimplifyLibCalls/2009-07-29-Exit2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyLibCalls/2009-07-29-Exit2.ll?rev=77512&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/SimplifyLibCalls/2009-07-29-Exit2.ll (added)
+++ llvm/trunk/test/Transforms/SimplifyLibCalls/2009-07-29-Exit2.ll Wed Jul 29 17:00:43 2009
@@ -0,0 +1,24 @@
+; RUN: llvm-as < %s | opt -simplify-libcalls -disable-output
+; PR4645
+
+define i32 @main() {
+entry:
+	br label %if.then
+
+lor.lhs.false:		; preds = %while.body
+	br i1 undef, label %if.then, label %for.cond
+
+if.then:		; preds = %lor.lhs.false, %while.body
+	call void @exit(i32 1)
+	br label %for.cond
+
+for.cond:		; preds = %for.end, %if.then, %lor.lhs.false
+	%j.0 = phi i32 [ %inc47, %for.end ], [ 0, %if.then ], [ 0, %lor.lhs.false ]		; <i32> [#uses=1]
+	unreachable
+
+for.end:		; preds = %for.cond20
+	%inc47 = add i32 %j.0, 1		; <i32> [#uses=1]
+	br label %for.cond
+}
+
+declare void @exit(i32)





More information about the llvm-commits mailing list