Skip to content

Commit 8b4469b

Browse files
authored
Merge pull request #73852 from meg-gupta/fixdce
Don't delete allocations in DCE
2 parents 33c76b6 + 505d84f commit 8b4469b

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
@@ -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+

0 commit comments

Comments
 (0)