Skip to content

Commit c92ff91

Browse files
authored
Merge pull request #82964 from meg-gupta/disablerrmotionnc
Disable retain and release sinking when rc root values are ~Copyable
2 parents 0eb0e42 + b8fcd72 commit c92ff91

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lib/SILOptimizer/Transforms/ARCCodeMotion.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,12 @@ void RetainCodeMotionContext::initializeCodeMotionDataFlow() {
433433
continue;
434434
if (!parentTransform->continueWithNextSubpassRun(&II))
435435
continue;
436+
SILValue Root = getRCRoot(&II);
437+
if (Root->getType().isMoveOnly()) {
438+
continue;
439+
}
436440
retainInstructions.insert(&II);
437441
RCInstructions.insert(&II);
438-
SILValue Root = getRCRoot(&II);
439442
if (RCRootIndex.find(Root) != RCRootIndex.end())
440443
continue;
441444
RCRootIndex[Root] = RCRootVault.size();
@@ -818,8 +821,11 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
818821
continue;
819822
if (!parentTransform->continueWithNextSubpassRun(&II))
820823
continue;
821-
releaseInstructions.insert(&II);
822824
SILValue Root = getRCRoot(&II);
825+
if (Root->getType().isMoveOnly()) {
826+
continue;
827+
}
828+
releaseInstructions.insert(&II);
823829
RCInstructions.insert(&II);
824830
if (RCRootIndex.find(Root) != RCRootIndex.end())
825831
continue;

test/SILOptimizer/retain_release_code_motion.sil

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,3 +1138,35 @@ bb0(%0 : $B, %1: $B):
11381138
return %5 : $()
11391139
}
11401140

1141+
enum NCEnum : ~Copyable {
1142+
case some([Int])
1143+
case none
1144+
}
1145+
1146+
sil @use_ncenum : $@convention(thin) (@guaranteed Array<Int>) -> ()
1147+
1148+
// CHECK-LABEL: sil hidden @testNoncopyable : $@convention(thin) (@guaranteed NCEnum) -> () {
1149+
// CHECK-NOT: retain_value %0
1150+
// CHECK: retain_value
1151+
// CHECK-LABEL: } // end sil function 'testNoncopyable'
1152+
sil hidden @testNoncopyable : $@convention(thin) (@guaranteed NCEnum) -> () {
1153+
bb0(%0 : $NCEnum):
1154+
switch_enum %0, case #NCEnum.none!enumelt: bb1, case #NCEnum.some!enumelt: bb2
1155+
1156+
bb1:
1157+
br bb3
1158+
1159+
bb2(%4 : $Array<Int>):
1160+
%5 = alloc_stack [var_decl] $Array<Int>, var, name "array"
1161+
retain_value %4
1162+
store %4 to %5
1163+
%11 = function_ref @use_ncenum : $@convention(thin) (@guaranteed Array<Int>) -> ()
1164+
%12 = apply %11(%4) : $@convention(thin) (@guaranteed Array<Int>) -> ()
1165+
destroy_addr %5
1166+
dealloc_stack %5
1167+
br bb3
1168+
bb3:
1169+
%16 = tuple ()
1170+
return %16
1171+
}
1172+

0 commit comments

Comments
 (0)