[llvm-commits] [llvm] r83996 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/invoke_unwind.ll
Chris Lattner
sabre at nondot.org
Tue Oct 13 11:13:06 PDT 2009
Author: lattner
Date: Tue Oct 13 13:13:05 2009
New Revision: 83996
URL: http://llvm.org/viewvc/llvm-project?rev=83996&view=rev
Log:
change simplifycfg to not duplicate 'unwind' instructions. Hopefully
this will increase the likelihood of common code getting sunk towards
the unwind.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/test/Transforms/SimplifyCFG/invoke_unwind.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=83996&r1=83995&r2=83996&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Tue Oct 13 13:13:05 2009
@@ -1860,33 +1860,26 @@
} else if (isa<UnwindInst>(BB->begin())) {
// Check to see if the first instruction in this block is just an unwind.
// If so, replace any invoke instructions which use this as an exception
- // destination with call instructions, and any unconditional branch
- // predecessor with an unwind.
+ // destination with call instructions.
//
SmallVector<BasicBlock*, 8> Preds(pred_begin(BB), pred_end(BB));
while (!Preds.empty()) {
BasicBlock *Pred = Preds.back();
- if (BranchInst *BI = dyn_cast<BranchInst>(Pred->getTerminator())) {
- if (BI->isUnconditional()) {
- Pred->getInstList().pop_back(); // nuke uncond branch
- new UnwindInst(Pred->getContext(), Pred); // Use unwind.
- Changed = true;
- }
- } else if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
+ if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
if (II->getUnwindDest() == BB) {
// Insert a new branch instruction before the invoke, because this
- // is now a fall through...
+ // is now a fall through.
BranchInst *BI = BranchInst::Create(II->getNormalDest(), II);
Pred->getInstList().remove(II); // Take out of symbol table
- // Insert the call now...
+ // Insert the call now.
SmallVector<Value*,8> Args(II->op_begin()+3, II->op_end());
CallInst *CI = CallInst::Create(II->getCalledValue(),
Args.begin(), Args.end(),
II->getName(), BI);
CI->setCallingConv(II->getCallingConv());
CI->setAttributes(II->getAttributes());
- // If the invoke produced a value, the Call now does instead
+ // If the invoke produced a value, the Call now does instead.
II->replaceAllUsesWith(CI);
delete II;
Changed = true;
Modified: llvm/trunk/test/Transforms/SimplifyCFG/invoke_unwind.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/invoke_unwind.ll?rev=83996&r1=83995&r2=83996&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/invoke_unwind.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/invoke_unwind.ll Tue Oct 13 13:13:05 2009
@@ -1,10 +1,9 @@
-; This testcase checks to see if the simplifycfg pass is converting invoke
-; instructions to call instructions if the handler just rethrows the exception.
-
; RUN: opt < %s -simplifycfg -S | FileCheck %s
declare void @bar()
+; This testcase checks to see if the simplifycfg pass is converting invoke
+; instructions to call instructions if the handler just rethrows the exception.
define i32 @test1() {
; CHECK: @test1
; CHECK-NEXT: call void @bar()
@@ -16,3 +15,19 @@
Rethrow: ; preds = %0
unwind
}
+
+
+; Verify that simplifycfg isn't duplicating 'unwind' instructions. Doing this
+; is bad because it discourages commoning.
+define i32 @test2(i1 %c) {
+; CHECK: @test2
+; CHECK: T:
+; CHECK-NEXT: call void @bar()
+; CHECK-NEXT: br label %F
+ br i1 %c, label %T, label %F
+T:
+ call void @bar()
+ br label %F
+F:
+ unwind
+}
More information about the llvm-commits
mailing list