Skip to content

Commit 899034b

Browse files
committed
EscapeUtils: handle load_borrow
1 parent 7b8f433 commit 899034b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
490490
// 1. the closure (with the captured values) itself can escape
491491
// 2. something can escape in a destructor when the context is destroyed
492492
return walkDownUses(ofValue: pai, path: path.with(knownType: nil))
493-
case is LoadInst, is LoadWeakInst, is LoadUnownedInst:
493+
case is LoadInst, is LoadWeakInst, is LoadUnownedInst, is LoadBorrowInst:
494494
if !followLoads(at: path.projectionPath) {
495495
return .continueWalk
496496
}
@@ -701,7 +701,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
701701
}
702702
case let ap as ApplyInst:
703703
return walkUpApplyResult(apply: ap, path: path.with(knownType: nil))
704-
case is LoadInst, is LoadWeakInst, is LoadUnownedInst:
704+
case is LoadInst, is LoadWeakInst, is LoadUnownedInst, is LoadBorrowInst:
705705
if !followLoads(at: path.projectionPath) {
706706
// When walking up we shouldn't end up at a load where followLoads is false,
707707
// because going from a (non-followLoads) address to a load always involves a class indirection.

test/SILOptimizer/escape_info.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ enum E {
7777
case B(Z)
7878
}
7979

80+
sil @escaping_argument : $@convention(thin) (@guaranteed Y) -> ()
81+
8082
sil @not_escaping_argument : $@convention(thin) (@guaranteed Z) -> () {
8183
[%0: noescape **]
8284
}
@@ -801,6 +803,32 @@ bb0:
801803
return %9 : $()
802804
}
803805

806+
// CHECK-LABEL: Escape information for test_load_borrow:
807+
// CHECK: global: %0 = alloc_ref $Y
808+
// CHECK: - : %1 = alloc_ref $Y
809+
// CHECK: End function test_load_borrow
810+
sil [ossa] @test_load_borrow : $@convention(thin) () -> () {
811+
bb0:
812+
%0 = alloc_ref $Y
813+
%1 = alloc_ref $Y
814+
%2 = alloc_stack $Y
815+
%3 = alloc_stack $Y
816+
store %0 to [init] %2 : $*Y
817+
store %1 to [init] %3 : $*Y
818+
%6 = load_borrow %2 : $*Y
819+
%7 = load_borrow %3 : $*Y
820+
%8 = function_ref @escaping_argument : $@convention(thin) (@guaranteed Y) -> ()
821+
%9 = apply %8(%6) : $@convention(thin) (@guaranteed Y) -> ()
822+
end_borrow %7 : $Y
823+
end_borrow %6 : $Y
824+
destroy_addr %3 : $*Y
825+
destroy_addr %2 : $*Y
826+
dealloc_stack %3 : $*Y
827+
dealloc_stack %2 : $*Y
828+
%r = tuple ()
829+
return %r : $()
830+
}
831+
804832
// CHECK-LABEL: Escape information for call_unknown:
805833
// CHECK: global: %0 = alloc_ref $X
806834
// CHECK: - : %1 = alloc_ref $Y

0 commit comments

Comments
 (0)