Skip to content

Commit 14fbee4

Browse files
committed
Update ConditionForwarding for @guaranteed forwarding phi support
1 parent 2a5f6a7 commit 14fbee4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/SILOptimizer/Transforms/ConditionForwarding.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ bool ConditionForwarding::tryOptimize(SwitchEnumInst *SEI) {
202202
if (!EI)
203203
return false;
204204

205+
if (getFunction()->hasOwnership() && EI->hasOperand()) {
206+
auto some = EI->getOperand();
207+
if (some->getOwnershipKind() == OwnershipKind::Guaranteed &&
208+
isa<SILFunctionArgument>(some)) {
209+
return false;
210+
}
211+
}
212+
205213
if (CommonBranchBlock && PredPred != CommonBranchBlock)
206214
return false;
207215
CommonBranchBlock = PredPred;

test/SILOptimizer/conditionforwarding_nontrivial_ossa.sil

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ bb6:
7171
return %r : $()
7272
}
7373

74-
// Currently, this is not optimized away because memory behavior of begin_borrow is conservative
74+
// Currently, this is not optimized away because enum has @guaranteed function argument, which
75+
// will need a borrow scope before being forwarded
7576
// CHECK-LABEL: sil [ossa] @simple_forwarding2 :
7677
// CHECK: switch_enum
7778
// CHECK-LABEL: } // end sil function 'simple_forwarding2'

0 commit comments

Comments
 (0)