Skip to content

Commit 12a137a

Browse files
Merge pull request #77401 from nate-chandler/rdar139235335
[CapturePromotion] dealloc_box doesn't mutate.
2 parents 1626b0f + 027070a commit 12a137a

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

lib/SILOptimizer/Mandatory/CapturePromotion.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,15 +1071,10 @@ class NonEscapingUserVisitor
10711071
ALWAYS_NON_ESCAPING_INST(StrongRelease)
10721072
ALWAYS_NON_ESCAPING_INST(DestroyValue)
10731073
ALWAYS_NON_ESCAPING_INST(EndBorrow)
1074+
ALWAYS_NON_ESCAPING_INST(DeallocBox)
1075+
ALWAYS_NON_ESCAPING_INST(EndAccess)
10741076
#undef ALWAYS_NON_ESCAPING_INST
10751077

1076-
bool visitDeallocBoxInst(DeallocBoxInst *dbi) {
1077-
markCurrentOpAsMutation();
1078-
return true;
1079-
}
1080-
1081-
bool visitEndAccessInst(EndAccessInst *) { return true; }
1082-
10831078
bool visitApplyInst(ApplyInst *ai) {
10841079
auto argIndex = currentOp.get()->getOperandNumber() - 1;
10851080
SILFunctionConventions substConv(ai->getSubstCalleeType(), ai->getModule());

test/SILOptimizer/capture_promotion_ownership.sil

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,39 @@ bb0:
555555
%28 = tuple ()
556556
return %28 : $()
557557
}
558+
559+
sil [ossa] @closable : $@convention(thin) (@guaranteed { var Bar }) -> Builtin.Int64 {
560+
entry(%box : @guaranteed ${ var Bar }):
561+
%retval = integer_literal $Builtin.Int64, 0
562+
return %retval : $Builtin.Int64
563+
}
564+
565+
// Test that a dealloc_box is not regarded as a mutation which would obstruct promotion.
566+
// CHECK-LABEL: sil [ossa] @with_dealloc_box : {{.*}} {
567+
// CHECK: load [copy]
568+
// CHECK-LABEL: } // end sil function 'with_dealloc_box'
569+
sil [ossa] @with_dealloc_box : $@convention(thin) (@owned Bar) -> () {
570+
entry(%idle_incoming : @owned $Bar):
571+
%box = alloc_box ${ var Bar }
572+
%box_borrow = begin_borrow [var_decl] %box : ${ var Bar }
573+
%box_addr = project_box %box_borrow : ${ var Bar }, 0
574+
store %idle_incoming to [init] %box_addr : $*Bar
575+
%closable = function_ref @closable : $@convention(thin) (@guaranteed { var Bar }) -> Builtin.Int64
576+
%box_copy = copy_value %box_borrow : ${ var Bar }
577+
mark_function_escape %box_addr : $*Bar
578+
%closure = partial_apply [callee_guaranteed] %closable(%box_copy) : $@convention(thin) (@guaranteed { var Bar }) -> Builtin.Int64
579+
cond_br undef, exit, die
580+
581+
die:
582+
destroy_value %closure : $@callee_guaranteed () -> Builtin.Int64
583+
end_borrow %box_borrow : ${ var Bar }
584+
dealloc_box %box : ${ var Bar }
585+
unreachable
586+
587+
exit:
588+
destroy_value %closure : $@callee_guaranteed () -> Builtin.Int64
589+
end_borrow %box_borrow : ${ var Bar }
590+
destroy_value %box : ${ var Bar }
591+
%retval = tuple ()
592+
return %retval :$()
593+
}

0 commit comments

Comments
 (0)