diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp --- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -94,10 +94,15 @@ auto *Term = BB.getTerminator(); - // Fow now only support `ret` function terminators. + // Fow now only support `ret`/`resume` function terminators. // FIXME: lift this restriction. - if (Term->getOpcode() != Instruction::Ret) + switch (Term->getOpcode()) { + case Instruction::Ret: + case Instruction::Resume: + break; + default: continue; + } // We can't tail-merge block that contains a musttail call. if (BB.getTerminatingMustTailCall()) diff --git a/llvm/test/Transforms/SimplifyCFG/tail-merge-resume.ll b/llvm/test/Transforms/SimplifyCFG/tail-merge-resume.ll --- a/llvm/test/Transforms/SimplifyCFG/tail-merge-resume.ll +++ b/llvm/test/Transforms/SimplifyCFG/tail-merge-resume.ll @@ -24,17 +24,20 @@ ; CHECK-NEXT: cleanup ; CHECK-NEXT: call void @baz() ; CHECK-NEXT: br i1 [[COND:%.*]], label [[RESUME0:%.*]], label [[RESUME1:%.*]] +; CHECK: common.resume: +; CHECK-NEXT: [[COMMON_RESUME_OP:%.*]] = phi { i8*, i32 } [ [[LP2:%.*]], [[LPAD2]] ], [ [[LP]], [[RESUME0]] ], [ [[LP]], [[RESUME1]] ] +; CHECK-NEXT: resume { i8*, i32 } [[COMMON_RESUME_OP]] ; CHECK: lpad2: -; CHECK-NEXT: [[LP2:%.*]] = landingpad { i8*, i32 } +; CHECK-NEXT: [[LP2]] = landingpad { i8*, i32 } ; CHECK-NEXT: cleanup ; CHECK-NEXT: call void @quuz() -; CHECK-NEXT: resume { i8*, i32 } [[LP2]] +; CHECK-NEXT: br label [[COMMON_RESUME:%.*]] ; CHECK: resume0: ; CHECK-NEXT: call void @qux() -; CHECK-NEXT: resume { i8*, i32 } [[LP]] +; CHECK-NEXT: br label [[COMMON_RESUME]] ; CHECK: resume1: ; CHECK-NEXT: call void @quux() -; CHECK-NEXT: resume { i8*, i32 } [[LP]] +; CHECK-NEXT: br label [[COMMON_RESUME]] ; invoke void @foo() to label %invoke.cont unwind label %lpad