Skip to content

Commit 164e9bb

Browse files
authored
Merge pull request #64713 from meg-gupta/dcefix5.9
[5.9] Don't DCE @owned phis that may have escaped
2 parents aebcd85 + 623d43f commit 164e9bb

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ void DCE::markLive() {
276276
}
277277
case SILInstructionKind::DestroyValueInst: {
278278
auto phi = PhiValue(I.getOperand(0));
279-
if (phi && phi->isLexical()) {
279+
// Disable DCE of phis which are lexical or may have a pointer escape.
280+
if (phi && (phi->isLexical() || hasPointerEscape(phi))) {
280281
markInstructionLive(&I);
281282
}
282283
break;

test/SILOptimizer/dead_code_elimination_nontrivial_ossa.sil

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,11 @@ bb0(%0 : $@sil_unmanaged AnyObject):
10221022

10231023
sil @foo : $@convention(thin) () -> ()
10241024

1025-
// CHECK-LABEL: sil [ossa] @test_escape : {{.*}} {
1025+
// CHECK-LABEL: sil [ossa] @test_escape1 : {{.*}} {
10261026
// CHECK: br bb1
10271027
// CHECK: end_borrow
1028-
// CHECK-LABEL: } // end sil function 'test_escape'
1029-
sil [ossa] @test_escape : $@convention(thin) () -> () {
1028+
// CHECK-LABEL: } // end sil function 'test_escape1'
1029+
sil [ossa] @test_escape1 : $@convention(thin) () -> () {
10301030
bb0:
10311031
%13 = function_ref @foo : $@convention(thin) () -> ()
10321032
%14 = partial_apply [callee_guaranteed] %13() : $@convention(thin) () -> ()
@@ -1044,6 +1044,27 @@ bb1(%21 : @owned $@noescape @callee_guaranteed () -> (), %22 : @guaranteed $@cal
10441044
return %28: $()
10451045
}
10461046

1047+
// CHECK-LABEL: sil [ossa] @test_escape2 : {{.*}} {
1048+
// CHECK: br bb1
1049+
// CHECK: destroy_value
1050+
// CHECK: destroy_value
1051+
// CHECK-LABEL: } // end sil function 'test_escape2'
1052+
sil [ossa] @test_escape2 : $@convention(thin) () -> () {
1053+
bb0:
1054+
%13 = function_ref @foo : $@convention(thin) () -> ()
1055+
%14 = partial_apply [callee_guaranteed] %13() : $@convention(thin) () -> ()
1056+
%15 = convert_escape_to_noescape %14 : $@callee_guaranteed () -> () to $@noescape @callee_guaranteed () -> ()
1057+
%18 = mark_dependence %15 : $@noescape @callee_guaranteed () -> () on %14 : $@callee_guaranteed () -> ()
1058+
br bb1(%18 : $@noescape @callee_guaranteed () -> (), %14 : $@callee_guaranteed () -> ())
1059+
1060+
bb1(%21 : @owned $@noescape @callee_guaranteed () -> (), %23 : @owned $@callee_guaranteed () -> ()):
1061+
%27 = apply %21() : $@noescape @callee_guaranteed () -> ()
1062+
destroy_value %21 : $@noescape @callee_guaranteed () -> ()
1063+
destroy_value %23 : $@callee_guaranteed () -> ()
1064+
%28 = tuple ()
1065+
return %28: $()
1066+
}
1067+
10471068
sil @use_klass : $@convention(thin) (@guaranteed Klass) -> ()
10481069

10491070
// CHECK-LABEL: sil [ossa] @test_forwarded_phi1 :

0 commit comments

Comments
 (0)