Skip to content

Commit a49d8ff

Browse files
authored
Merge pull request #77061 from meg-gupta/dcecast
DCE unconditional_checked_cast
2 parents 5d4e1d0 + 359f6d1 commit a49d8ff

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ static bool seemsUseful(SILInstruction *I) {
5555
isa<EndBorrowInst>(I))
5656
return false;
5757

58+
if (isa<UnconditionalCheckedCastInst>(I)) {
59+
return false;
60+
}
61+
5862
// A load [copy] is okay to be DCE'ed if there are no useful dependencies
5963
if (auto *load = dyn_cast<LoadInst>(I)) {
6064
if (load->getOwnershipQualifier() == LoadOwnershipQualifier::Copy)

test/SILOptimizer/dead_code_elimination.sil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,18 @@ bb0(%0 : $*Container):
270270
%999 = tuple ()
271271
return %999 : $()
272272
}
273+
274+
class B {}
275+
276+
// CHECK-LABEL: sil @dead_unconditional_checked_cast
277+
// CHECK-NOT: unconditional_checked_cast
278+
// CHECK-LABEL: end sil function 'dead_unconditional_checked_cast'
279+
sil @dead_unconditional_checked_cast : $@convention(thin) (B, B) -> () {
280+
bb0(%0 : $B, %1: $B):
281+
strong_retain %0: $B
282+
apply undef() : $@convention(thin) () -> ()
283+
%3 = unconditional_checked_cast %0 : $B to Builtin.NativeObject
284+
strong_release %0: $B
285+
%5 = tuple()
286+
return %5 : $()
287+
}

0 commit comments

Comments
 (0)