Skip to content

[6.2] Disable retain and release sinking when rc root values are ~Copyable #82974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/SILOptimizer/Transforms/ARCCodeMotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,12 @@ void RetainCodeMotionContext::initializeCodeMotionDataFlow() {
continue;
if (!parentTransform->continueWithNextSubpassRun(&II))
continue;
SILValue Root = getRCRoot(&II);
if (Root->getType().isMoveOnly()) {
continue;
}
retainInstructions.insert(&II);
RCInstructions.insert(&II);
SILValue Root = getRCRoot(&II);
if (RCRootIndex.find(Root) != RCRootIndex.end())
continue;
RCRootIndex[Root] = RCRootVault.size();
Expand Down Expand Up @@ -818,8 +821,11 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
continue;
if (!parentTransform->continueWithNextSubpassRun(&II))
continue;
releaseInstructions.insert(&II);
SILValue Root = getRCRoot(&II);
if (Root->getType().isMoveOnly()) {
continue;
}
releaseInstructions.insert(&II);
RCInstructions.insert(&II);
if (RCRootIndex.find(Root) != RCRootIndex.end())
continue;
Expand Down
32 changes: 32 additions & 0 deletions test/SILOptimizer/retain_release_code_motion.sil
Original file line number Diff line number Diff line change
Expand Up @@ -1138,3 +1138,35 @@ bb0(%0 : $B, %1: $B):
return %5 : $()
}

enum NCEnum : ~Copyable {
case some([Int])
case none
}

sil @use_ncenum : $@convention(thin) (@guaranteed Array<Int>) -> ()

// CHECK-LABEL: sil hidden @testNoncopyable : $@convention(thin) (@guaranteed NCEnum) -> () {
// CHECK-NOT: retain_value %0
// CHECK: retain_value
// CHECK-LABEL: } // end sil function 'testNoncopyable'
sil hidden @testNoncopyable : $@convention(thin) (@guaranteed NCEnum) -> () {
bb0(%0 : $NCEnum):
switch_enum %0, case #NCEnum.none!enumelt: bb1, case #NCEnum.some!enumelt: bb2

bb1:
br bb3

bb2(%4 : $Array<Int>):
%5 = alloc_stack [var_decl] $Array<Int>, var, name "array"
retain_value %4
store %4 to %5
%11 = function_ref @use_ncenum : $@convention(thin) (@guaranteed Array<Int>) -> ()
%12 = apply %11(%4) : $@convention(thin) (@guaranteed Array<Int>) -> ()
destroy_addr %5
dealloc_stack %5
br bb3
bb3:
%16 = tuple ()
return %16
}