Skip to content

Commit 2fb3f46

Browse files
authored
Merge pull request #61146 from meg-gupta/dcefollowup
Follow up of #61126
2 parents 4ae536e + a1bcf17 commit 2fb3f46

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ inline bool isForwardingConsume(SILValue value) {
7878
return canOpcodeForwardOwnedValues(value);
7979
}
8080

81-
bool hasEscaped(BorrowedValue value);
81+
bool hasPointerEscape(BorrowedValue value);
8282

8383
/// Find leaf "use points" of \p guaranteedValue that determine its lifetime
8484
/// requirement. Return true if no PointerEscape use was found.

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
using namespace swift;
2727

28-
bool swift::hasEscaped(BorrowedValue value) {
28+
bool swift::hasPointerEscape(BorrowedValue value) {
29+
assert(value.kind == BorrowedValueKind::BeginBorrow ||
30+
value.kind == BorrowedValueKind::LoadBorrow);
2931
GraphNodeWorklist<Operand *, 8> worklist;
3032
for (Operand *use : value->getUses()) {
3133
if (use->getOperandOwnership() != OperandOwnership::NonUse)
@@ -42,14 +44,14 @@ bool swift::hasEscaped(BorrowedValue value) {
4244

4345
case OperandOwnership::ForwardingUnowned:
4446
case OperandOwnership::PointerEscape:
45-
case OperandOwnership::BitwiseEscape:
4647
return true;
4748

4849
case OperandOwnership::Borrow:
4950
case OperandOwnership::EndBorrow:
5051
case OperandOwnership::InstantaneousUse:
5152
case OperandOwnership::UnownedInstantaneousUse:
5253
case OperandOwnership::InteriorPointer:
54+
case OperandOwnership::BitwiseEscape:
5355
break;
5456

5557
case OperandOwnership::Reborrow: {

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ void DCE::markLive() {
303303
}
304304
// Populate reborrowDependencies for this borrow
305305
findReborrowDependencies(borrowInst);
306-
if (hasEscaped(BorrowedValue(borrowInst))) {
306+
// Don't optimize a borrow scope if it is lexical or has a pointer
307+
// escape.
308+
if (borrowInst->isLexical() ||
309+
hasPointerEscape(BorrowedValue(borrowInst))) {
307310
// Visit all end_borrows and mark them live
308311
visitTransitiveEndBorrows(borrowInst, [&](EndBorrowInst *endBorrow) {
309312
markInstructionLive(endBorrow);

0 commit comments

Comments
 (0)