Skip to content

Commit 9ce2681

Browse files
committed
Update utility which checks if scope ending instructions in OSSA can be trivially deleted
1 parent b6cf3cd commit 9ce2681

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ swift::createDecrementBefore(SILValue ptr, SILInstruction *insertPt) {
120120
return builder.createReleaseValue(loc, ptr, builder.getDefaultAtomicity());
121121
}
122122

123-
static bool isOSSAEndScopeWithNoneOperand(SILInstruction *i) {
123+
/// Returns true if OSSA scope ending instructions end_borrow/destroy_value can
124+
/// be deleted trivially
125+
static bool canTriviallyDeleteOSSAEndScopeInst(SILInstruction *i) {
124126
if (!isa<EndBorrowInst>(i) && !isa<DestroyValueInst>(i))
125127
return false;
128+
if (isa<StoreBorrowInst>(i->getOperand(0)))
129+
return false;
126130
return i->getOperand(0)->getOwnershipKind() == OwnershipKind::None;
127131
}
128132

@@ -172,7 +176,7 @@ bool swift::isInstructionTriviallyDead(SILInstruction *inst) {
172176
//
173177
// Examples of ossa end_scope instructions: end_borrow, destroy_value.
174178
if (inst->getFunction()->hasOwnership() &&
175-
isOSSAEndScopeWithNoneOperand(inst))
179+
canTriviallyDeleteOSSAEndScopeInst(inst))
176180
return true;
177181

178182
if (!inst->mayHaveSideEffects())

0 commit comments

Comments
 (0)