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 {
4040// FIXME: Reconcile the similarities between this and
4141// isInstructionTriviallyDead.
4242static 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+
4348 if (I->mayHaveSideEffects ())
4449 return true ;
4550
@@ -258,6 +263,10 @@ void DCE::markLive(SILFunction &F) {
258263 }
259264 continue ;
260265 }
266+ if (auto *endAccess = dyn_cast<EndAccessInst>(&I)) {
267+ addReverseDependency (endAccess->getBeginAccess (), &I);
268+ continue ;
269+ }
261270 if (seemsUseful (&I))
262271 markValueLive (&I);
263272 }
Original file line number Diff line number Diff line change @@ -259,3 +259,21 @@ bb2:
259259bb3:
260260 br bb1
261261}
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