1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[SimplifyCFG] Tail-merging all blocks with resume terminator

Similar to what we already do for `ret` terminators.
As noted by @rnk, clang seems to already generate a single `ret`/`resume`,
so this isn't likely to cause widespread changes.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D104849
This commit is contained in:
Roman Lebedev 2021-06-24 21:25:06 +03:00
parent 0394084380
commit a6fe9f4fd8
2 changed files with 15 additions and 9 deletions

View File

@ -94,10 +94,15 @@ static bool tailMergeBlocksWithSimilarFunctionTerminators(Function &F,
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())

View File

@ -39,19 +39,20 @@ define void @merge_simple(i1 %cond) personality i8* bitcast (i32 (...)* @__gxx_p
; CHECK-NEXT: cleanup
; CHECK-NEXT: call void @baz()
; CHECK-NEXT: br label [[RESUME2]]
; CHECK: common.resume:
; CHECK-NEXT: [[COMMON_RESUME_OP:%.*]] = phi { i8*, i32 } [ [[LP]], [[RESUME0]] ], [ [[LP]], [[RESUME1]] ], [ [[SEMICOMMON_LP:%.*]], [[RESUME2]] ]
; CHECK-NEXT: call void @common()
; CHECK-NEXT: resume { i8*, i32 } [[COMMON_RESUME_OP]]
; CHECK: resume0:
; CHECK-NEXT: call void @qux()
; CHECK-NEXT: call void @common()
; CHECK-NEXT: resume { i8*, i32 } [[LP]]
; CHECK-NEXT: br label [[COMMON_RESUME:%.*]]
; CHECK: resume1:
; CHECK-NEXT: call void @quux()
; CHECK-NEXT: call void @common()
; CHECK-NEXT: resume { i8*, i32 } [[LP]]
; CHECK-NEXT: br label [[COMMON_RESUME]]
; CHECK: resume2:
; CHECK-NEXT: [[SEMICOMMON_LP:%.*]] = phi { i8*, i32 } [ [[LP2]], [[LPAD2]] ], [ [[LP3]], [[LPAD3]] ]
; CHECK-NEXT: [[SEMICOMMON_LP]] = phi { i8*, i32 } [ [[LP2]], [[LPAD2]] ], [ [[LP3]], [[LPAD3]] ]
; CHECK-NEXT: call void @quuz()
; CHECK-NEXT: call void @common()
; CHECK-NEXT: resume { i8*, i32 } [[SEMICOMMON_LP]]
; CHECK-NEXT: br label [[COMMON_RESUME]]
;
invoke void @maybe_throws() to label %invoke.cont unwind label %lpad