File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -1203,3 +1203,20 @@ sil [ossa] @dont_dce_lexical_phi : $() -> () {
12031203 return %retval : $()
12041204}
12051205
1206+ class KlassWithDeinit {
1207+ init()
1208+ deinit
1209+ }
1210+
1211+ // DCE should not delete dead allocations, leave it to DOE
1212+ // CHECK-LABEL: sil [ossa] @dont_delete_allocation :
1213+ // CHECK: alloc_ref
1214+ // CHECK-LABEL: } // end sil function 'dont_delete_allocation'
1215+ sil [ossa] @dont_delete_allocation : $@convention(thin) () -> () {
1216+ bb0:
1217+ %a = alloc_ref $KlassWithDeinit
1218+ destroy_value %a : $KlassWithDeinit
1219+ %t = tuple ()
1220+ return %t : $()
1221+ }
1222+
You can’t perform that action at this time.
0 commit comments