[SimplifyCFG] 'merge compatible invokes': don't create trivial PHI's with all-identical incoming values

This commit is contained in:
Roman Lebedev 2022-02-08 21:16:39 +03:00
parent e2aed0b047
commit 414b47645d
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
2 changed files with 11 additions and 11 deletions

View File

@ -2438,14 +2438,16 @@ static void MergeCompatibleInvokesImpl(ArrayRef<InvokeInst *> Invokes,
// Form the merged data operands for the merged invoke.
for (Use &U : MergedInvoke->data_ops()) {
Type *Ty = U->getType();
if (Ty->isTokenTy())
continue; // Keep this arg as-is, we've checked that all the invokes
// recieve the *same* token value.
// Don't create trivial PHI's with all-identical incoming values.
bool NeedPHI = any_of(Invokes, [&U](InvokeInst *II) {
return II->getOperand(U.getOperandNo()) != U.get();
});
if (!NeedPHI)
continue;
// Otherwise, simply form a PHI out of all the data ops under this index.
PHINode *PN = PHINode::Create(Ty, /*NumReservedValues=*/Invokes.size(), "",
MergedInvoke);
// Form a PHI out of all the data ops under this index.
PHINode *PN = PHINode::Create(
U->getType(), /*NumReservedValues=*/Invokes.size(), "", MergedInvoke);
for (InvokeInst *II : Invokes) {
Use *IVU = II->data_operands_begin() + MergedInvoke->getDataOperandNo(&U);
PN->addIncoming(IVU->get(), II->getParent());

View File

@ -696,8 +696,7 @@ define void @t12_arguments_are_fine() personality i8* bitcast (i32 (...)* @__gxx
; CHECK-NEXT: [[C1:%.*]] = call i1 @cond()
; CHECK-NEXT: br i1 [[C1]], label [[IF_THEN1_INVOKE]], label [[IF_END:%.*]]
; CHECK: if.then1.invoke:
; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ 42, [[IF_ELSE]] ], [ 42, [[ENTRY:%.*]] ]
; CHECK-NEXT: invoke void @simple_throw_taking_argument(i32 [[TMP0]])
; CHECK-NEXT: invoke void @simple_throw_taking_argument(i32 42)
; CHECK-NEXT: to label [[IF_THEN1_CONT:%.*]] unwind label [[LPAD:%.*]]
; CHECK: if.then1.cont:
; CHECK-NEXT: unreachable
@ -1136,8 +1135,7 @@ define void @t19_compatible_operand_bundle() personality i8* bitcast (i32 (...)*
; CHECK-NEXT: [[C1:%.*]] = call i1 @cond()
; CHECK-NEXT: br i1 [[C1]], label [[IF_THEN1_INVOKE]], label [[IF_END:%.*]]
; CHECK: if.then1.invoke:
; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ 42, [[IF_ELSE]] ], [ 42, [[ENTRY:%.*]] ]
; CHECK-NEXT: invoke void @simple_throw() [ "abc"(i32 [[TMP0]]) ]
; CHECK-NEXT: invoke void @simple_throw() [ "abc"(i32 42) ]
; CHECK-NEXT: to label [[IF_THEN1_CONT:%.*]] unwind label [[LPAD:%.*]]
; CHECK: if.then1.cont:
; CHECK-NEXT: unreachable