File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,11 @@ namespace {
40
40
// FIXME: Reconcile the similarities between this and
41
41
// isInstructionTriviallyDead.
42
42
static bool seemsUseful (SILInstruction *I) {
43
+ // begin_access is defined to have side effects, but this is not relevant for
44
+ // DCE.
45
+ if (isa<BeginAccessInst>(I))
46
+ return false ;
47
+
43
48
if (I->mayHaveSideEffects ())
44
49
return true ;
45
50
@@ -258,6 +263,10 @@ void DCE::markLive(SILFunction &F) {
258
263
}
259
264
continue ;
260
265
}
266
+ if (auto *endAccess = dyn_cast<EndAccessInst>(&I)) {
267
+ addReverseDependency (endAccess->getBeginAccess (), &I);
268
+ continue ;
269
+ }
261
270
if (seemsUseful (&I))
262
271
markValueLive (&I);
263
272
}
Original file line number Diff line number Diff line change @@ -259,3 +259,21 @@ bb2:
259
259
bb3:
260
260
br bb1
261
261
}
262
+
263
+ // Check that DCE eliminates dead access instructions.
264
+ // CHECK-LABEL: sil @dead_access
265
+ // CHECK: bb0
266
+ // CHECK-NEXT: tuple
267
+ // CHECK-NEXT: return
268
+ // CHECK-LABEL: end sil function 'dead_access'
269
+ sil @dead_access : $@convention(thin) (@in Container) -> () {
270
+ bb0(%0 : $*Container):
271
+ %1 = begin_access [modify] [dynamic] %0 : $*Container
272
+ end_access %1 : $*Container
273
+
274
+ %3 = begin_access [read] [static] %0 : $*Container
275
+ end_access %3 : $*Container
276
+
277
+ %999 = tuple ()
278
+ return %999 : $()
279
+ }
You can’t perform that action at this time.
0 commit comments