Skip to content

Commit e9d2261

Browse files
authored
Merge pull request #73858 from meg-gupta/fixdcecp
[6.0] Don't delete allocations in DCE
2 parents 89ca077 + 476a7f9 commit e9d2261

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ static bool seemsUseful(SILInstruction *I) {
8181
if (isa<DebugValueInst>(I))
8282
return isa<SILFunctionArgument>(I->getOperand(0))
8383
|| isa<SILUndef>(I->getOperand(0));
84+
85+
86+
// Don't delete allocation instructions in DCE.
87+
if (isa<AllocRefInst>(I) || isa<AllocRefDynamicInst>(I)) {
88+
return true;
89+
}
8490

8591
return false;
8692
}

test/SILOptimizer/dead_code_elimination_nontrivial_ossa.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,3 +1196,20 @@ sil [ossa] @dont_dce_lexical_phi : $() -> () {
11961196
return %retval : $()
11971197
}
11981198

1199+
class KlassWithDeinit {
1200+
init()
1201+
deinit
1202+
}
1203+
1204+
// DCE should not delete dead allocations, leave it to DOE
1205+
// CHECK-LABEL: sil [ossa] @dont_delete_allocation :
1206+
// CHECK: alloc_ref
1207+
// CHECK-LABEL: } // end sil function 'dont_delete_allocation'
1208+
sil [ossa] @dont_delete_allocation : $@convention(thin) () -> () {
1209+
bb0:
1210+
%a = alloc_ref $KlassWithDeinit
1211+
destroy_value %a : $KlassWithDeinit
1212+
%t = tuple ()
1213+
return %t : $()
1214+
}
1215+

0 commit comments

Comments
 (0)