summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-05-21 05:12:32 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-05-21 05:12:32 +0000
commit9f92f4c497734abc8104a3b2219fdae765691e13 (patch)
tree20f73c40ba9e751f44ff9450e4b239e20b25d7c5
parent73f48f4662f30b837743a02ab9256558521fb20a (diff)
downloadbcm5719-llvm-9f92f4c497734abc8104a3b2219fdae765691e13.tar.gz
bcm5719-llvm-9f92f4c497734abc8104a3b2219fdae765691e13.zip
[SimplifyCFG] Remove cleanuppads which are empty except for calls to lifetime.end
A cleanuppad is not cheap, they turn into many instructions and result in additional spills and fills. It is not worth keeping a cleanuppad around if all it does is hold a lifetime.end instruction. N.B. We first try to merge the cleanuppad with another cleanuppad to avoid dropping the lifetime and debug info markers. llvm-svn: 270314
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp22
-rw-r--r--llvm/test/Transforms/SimplifyCFG/empty-cleanuppad.ll31
2 files changed, 48 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index fb6a13fadc5..25baf1bf640 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3424,11 +3424,23 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI) {
// This isn't an empty cleanup.
return false;
- // Check that there are no other instructions except for debug intrinsics.
+ // Check that there are no other instructions except for benign intrinsics.
BasicBlock::iterator I = CPInst->getIterator(), E = RI->getIterator();
- while (++I != E)
- if (!isa<DbgInfoIntrinsic>(I))
+ while (++I != E) {
+ auto *II = dyn_cast<IntrinsicInst>(I);
+ if (!II)
+ return false;
+
+ Intrinsic::ID IntrinsicID = II->getIntrinsicID();
+ switch (IntrinsicID) {
+ case Intrinsic::dbg_declare:
+ case Intrinsic::dbg_value:
+ case Intrinsic::lifetime_end:
+ break;
+ default:
return false;
+ }
+ }
// If the cleanup return we are simplifying unwinds to the caller, this will
// set UnwindDest to nullptr.
@@ -3567,10 +3579,10 @@ bool SimplifyCFGOpt::SimplifyCleanupReturn(CleanupReturnInst *RI) {
if (isa<UndefValue>(RI->getOperand(0)))
return false;
- if (removeEmptyCleanup(RI))
+ if (mergeCleanupPad(RI))
return true;
- if (mergeCleanupPad(RI))
+ if (removeEmptyCleanup(RI))
return true;
return false;
diff --git a/llvm/test/Transforms/SimplifyCFG/empty-cleanuppad.ll b/llvm/test/Transforms/SimplifyCFG/empty-cleanuppad.ll
index 57b36288995..e83cbb50e58 100644
--- a/llvm/test/Transforms/SimplifyCFG/empty-cleanuppad.ll
+++ b/llvm/test/Transforms/SimplifyCFG/empty-cleanuppad.ll
@@ -404,6 +404,35 @@ catch.cont: ; preds = %catch
return: ; preds = %invoke.cont, %catch.cont
ret void
}
+; CHECK-LABEL: define i32 @f9()
+; CHECK: entry:
+; CHECK: invoke void @"\01??1S2@@QEAA@XZ"(
+; CHECK-NOT: cleanuppad
+; CHECK: catch.dispatch:
+; CHECK: }
+define i32 @f9() personality i32 (...)* @__CxxFrameHandler3 {
+entry:
+ %s = alloca i8, align 1
+ call void @llvm.lifetime.start(i64 1, i8* nonnull %s)
+ %bc = bitcast i8* %s to %struct.S2*
+ invoke void @"\01??1S2@@QEAA@XZ"(%struct.S2* %bc)
+ to label %try.cont unwind label %ehcleanup
+
+ehcleanup:
+ %cleanup.pad = cleanuppad within none []
+ call void @llvm.lifetime.end(i64 1, i8* nonnull %s)
+ cleanupret from %cleanup.pad unwind label %catch.dispatch
+
+catch.dispatch:
+ %catch.switch = catchswitch within none [label %catch] unwind to caller
+
+catch:
+ %catch.pad = catchpad within %catch.switch [i8* null, i32 0, i8* null]
+ catchret from %catch.pad to label %try.cont
+
+try.cont:
+ ret i32 0
+}
%struct.S = type { i8 }
%struct.S2 = type { i8 }
@@ -413,3 +442,5 @@ declare void @use_x(i32 %x)
declare i32 @__CxxFrameHandler3(...)
+declare void @llvm.lifetime.start(i64, i8* nocapture)
+declare void @llvm.lifetime.end(i64, i8* nocapture)
OpenPOWER on IntegriCloud