Skip to content

Commit 000a33f

Browse files
committed
[MoveOnlyAddressChecker] Don't destroy borrows.
If a marked location is used by `store_borrow`s, then all its users are `store_borrow`s or `dealloc_stack`s, so there's nothing to destroy.
1 parent 16e080d commit 000a33f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,6 +3037,13 @@ static void insertDestroyBeforeInstruction(UseState &addressUseState,
30373037
SILValue baseAddress,
30383038
SmallBitVector &bv,
30393039
ConsumeInfo &consumes) {
3040+
if (!baseAddress->getUsersOfType<StoreBorrowInst>().empty()) {
3041+
// If there are _any_ store_borrow users, then all users of the address are
3042+
// store_borrows (and dealloc_stacks). Nothing is stored, there's nothing
3043+
// to destroy.
3044+
return;
3045+
}
3046+
30403047
// If we need all bits...
30413048
if (bv.all()) {
30423049
// And our next instruction is a destroy_addr on the base address, just

test/SILOptimizer/moveonly_addresschecker_unmaximized.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct M4: ~Copyable {
2323

2424
sil @get_M4 : $@convention(thin) () -> @owned M4
2525
sil @end_2 : $@convention(thin) (@owned M, @owned M) -> ()
26+
sil @see_addr : $@convention(thin) (@in_guaranteed M) -> ()
2627
sil @see_addr_2 : $@convention(thin) (@in_guaranteed M, @in_guaranteed M) -> ()
2728
sil @replace_2 : $@convention(thin) (@inout M, @inout M) -> ()
2829
sil @get_out_2 : $@convention(thin) () -> (@out M, @out M)
@@ -235,3 +236,20 @@ bb0(%m_in : @owned $M):
235236
apply %die(%pa) : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never
236237
unreachable
237238
}
239+
240+
// CHECK-LABEL: sil [ossa] @dont_destroy_store_borrowed_addr : {{.*}} {
241+
// CHECK-NOT: destroy_addr
242+
// CHECK-LABEL: } // end sil function 'dont_destroy_store_borrowed_addr'
243+
sil [ossa] @dont_destroy_store_borrowed_addr : $@convention(thin) (@guaranteed M) -> () {
244+
bb0(%0 : @guaranteed $M):
245+
%stack = alloc_stack $M
246+
%mark = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack : $*M
247+
%borrow = store_borrow %0 to %mark : $*M
248+
%see_addr = function_ref @see_addr : $@convention(thin) (@in_guaranteed M) -> ()
249+
apply %see_addr(%borrow) : $@convention(thin) (@in_guaranteed M) -> ()
250+
end_borrow %borrow : $*M
251+
dealloc_stack %stack : $*M
252+
%retval = tuple ()
253+
return %retval : $()
254+
}
255+

0 commit comments

Comments
 (0)