Index: lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- lib/Transforms/Utils/SimplifyCFG.cpp +++ lib/Transforms/Utils/SimplifyCFG.cpp @@ -2910,11 +2910,17 @@ // caused control to branch here. return false; - // Check that there are no other instructions except for debug intrinsics. + // Check that there are no other instructions except for debug and lifetime + // intrinsics. BasicBlock::iterator I = LPInst, E = RI; while (++I != E) - if (!isa(I)) + if (!isa(I)) { + if (auto *II = dyn_cast(I)) + if (II->getIntrinsicID() == Intrinsic::lifetime_start || + II->getIntrinsicID() == Intrinsic::lifetime_end) + continue; return false; + } // Turn all invokes that unwind here into calls and delete the basic block. for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE;) { Index: test/Transforms/SimplifyCFG/empty-cleanup.ll =================================================================== --- /dev/null +++ test/Transforms/SimplifyCFG/empty-cleanup.ll @@ -0,0 +1,23 @@ +; RUN: opt -simplifycfg -S < %s | FileCheck %s + +declare i32 @__gxx_personality_v0(...) +declare void @callee() + +declare void @llvm.lifetime.start(i64, i8* nocapture) +declare void @llvm.lifetime.end(i64, i8* nocapture) + +define void @test() personality i32 (...)* @__gxx_personality_v0 { + %a = alloca i8 +;CHECK: call void @callee + invoke void @callee() + to label %normal unwind label %unwind + +normal: + ret void + +unwind: + %exn = landingpad {i8*, i32} catch i8* null + call void @llvm.lifetime.start(i64 1, i8* %a) + call void @llvm.lifetime.end(i64 1, i8* %a) + resume { i8*, i32 } %exn +}