File tree Expand file tree Collapse file tree 2 files changed +47
-4
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +47
-4
lines changed Original file line number Diff line number Diff line change @@ -45,10 +45,11 @@ namespace {
4545// FIXME: Reconcile the similarities between this and
4646// isInstructionTriviallyDead.
4747static bool seemsUseful (SILInstruction *I) {
48- // Even though begin_access/destroy_value/copy_value have side-effects, they
49- // can be DCE'ed if they do not have useful dependencies/reverse dependencies
48+ // Even though begin_access/destroy_value/copy_value/end_lifetime have
49+ // side-effects, they can be DCE'ed if they do not have useful
50+ // dependencies/reverse dependencies
5051 if (isa<BeginAccessInst>(I) || isa<CopyValueInst>(I) ||
51- isa<DestroyValueInst>(I))
52+ isa<DestroyValueInst>(I) || isa<EndLifetimeInst>(I) )
5253 return false ;
5354
5455 // A load [copy] is okay to be DCE'ed if there are no useful dependencies
@@ -268,7 +269,8 @@ void DCE::markLive() {
268269 break ;
269270 }
270271 case SILInstructionKind::DestroyValueInst:
271- case SILInstructionKind::EndBorrowInst: {
272+ case SILInstructionKind::EndBorrowInst:
273+ case SILInstructionKind::EndLifetimeInst: {
272274 // The instruction is live only if it's operand value is also live
273275 addReverseDependency (I.getOperand (0 ), &I);
274276 break ;
Original file line number Diff line number Diff line change @@ -611,3 +611,44 @@ bb3:
611611 return %9999 : $()
612612}
613613
614+ // CHECK-LABEL: sil [ossa] @dce_deadendlifetime1 :
615+ // CHECK-NOT: end_lifetime
616+ // CHECK-LABEL: } // end sil function 'dce_deadendlifetime1'
617+ sil [ossa] @dce_deadendlifetime1 : $@convention(thin) () -> () {
618+ bb0:
619+ cond_br undef, bb1, bb2
620+
621+ bb1:
622+ br bb3(undef : $Klass)
623+
624+ bb2:
625+ br bb3(undef : $Klass)
626+
627+ bb3(%2 : @owned $Klass):
628+ end_lifetime %2 : $Klass
629+ %res = tuple ()
630+ return %res : $()
631+ }
632+
633+ // CHECK-LABEL: sil [ossa] @dce_deadendlifetime2 :
634+ // CHECK-NOT: end_lifetime
635+ // CHECK-LABEL: } // end sil function 'dce_deadendlifetime2'
636+ sil [ossa] @dce_deadendlifetime2 : $@convention(thin) () -> () {
637+ bb0:
638+ cond_br undef, bb1, bb2
639+
640+ bb1:
641+ br bb3(undef : $Klass)
642+
643+ bb2:
644+ br bb3(undef : $Klass)
645+
646+ bb3(%2 : @owned $Klass):
647+ br bb4(%2 : $Klass)
648+
649+ bb4(%3 : @owned $Klass):
650+ end_lifetime %3 : $Klass
651+ %res = tuple ()
652+ return %res : $()
653+ }
654+
You can’t perform that action at this time.
0 commit comments