File tree Expand file tree Collapse file tree 2 files changed +25
-13
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +25
-13
lines changed Original file line number Diff line number Diff line change @@ -43,21 +43,18 @@ namespace {
4343// FIXME: Reconcile the similarities between this and
4444// isInstructionTriviallyDead.
4545static bool seemsUseful (SILInstruction *I) {
46- // begin_access is defined to have side effects, but this is not relevant for
47- // DCE.
48- if (isa<BeginAccessInst>(I))
46+ // Even though begin_access/begin_borrow/destroy_value/copy_value have
47+ // side-effects, they can be DCE'ed if they do not have useful
48+ // dependencies/reverse dependencies
49+ if (isa<BeginAccessInst>(I) || isa<BeginBorrowInst>(I) ||
50+ isa<CopyValueInst>(I) || isa<DestroyValueInst>(I))
4951 return false ;
5052
51- // Even though begin_borrow/destroy_value/copy_value have side-effects, they
52- // can be DCE'ed if they do not have useful dependencies/reverse dependencies
53- if (isa<BeginBorrowInst>(I))
54- return false ;
55-
56- if (isa<DestroyValueInst>(I))
57- return false ;
58-
59- if (isa<CopyValueInst>(I))
60- return false ;
53+ // A load [copy] is okay to be DCE'ed if there are no useful dependencies
54+ if (auto *load = dyn_cast<LoadInst>(I)) {
55+ if (load->getOwnershipQualifier () == LoadOwnershipQualifier::Copy)
56+ return false ;
57+ }
6158
6259 if (I->mayHaveSideEffects ())
6360 return true ;
Original file line number Diff line number Diff line change @@ -218,6 +218,21 @@ bb3(%2 : @owned $Klass):
218218 return %res : $()
219219}
220220
221+ // CHECK-LABEL: sil [ossa] @dce_deadcopy7 :
222+ // CHECK-NOT: load [copy]
223+ // CHECK-LABEL: } // end sil function 'dce_deadcopy7'
224+ sil [ossa] @dce_deadcopy7 : $@convention(thin) (@in Klass) -> () {
225+ bb0(%0 : $*Klass):
226+ %1 = load [copy] %0 : $*Klass
227+ br bb1(%1 : $Klass)
228+
229+ bb1(%2 : @owned $Klass):
230+ destroy_value %2 : $Klass
231+ destroy_addr %0 : $*Klass
232+ %res = tuple ()
233+ return %res : $()
234+ }
235+
221236// CHECK-LABEL: sil [ossa] @dce_destructure1 :
222237// CHECK: bb0(%0 : {{.*}})
223238// CHECK-NEXT: destroy_value %0
You can’t perform that action at this time.
0 commit comments