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 {
43
43
// FIXME: Reconcile the similarities between this and
44
44
// isInstructionTriviallyDead.
45
45
static 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))
49
51
return false ;
50
52
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
+ }
61
58
62
59
if (I->mayHaveSideEffects ())
63
60
return true ;
Original file line number Diff line number Diff line change @@ -218,6 +218,21 @@ bb3(%2 : @owned $Klass):
218
218
return %res : $()
219
219
}
220
220
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
+
221
236
// CHECK-LABEL: sil [ossa] @dce_destructure1 :
222
237
// CHECK: bb0(%0 : {{.*}})
223
238
// CHECK-NEXT: destroy_value %0
You can’t perform that action at this time.
0 commit comments