Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/SILOptimizer/Transforms/DeadCodeElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ namespace {
// FIXME: Reconcile the similarities between this and
// isInstructionTriviallyDead.
static bool seemsUseful(SILInstruction *I) {
// begin_access is defined to have side effects, but this is not relevant for
// DCE.
if (isa<BeginAccessInst>(I))
return false;

if (I->mayHaveSideEffects())
return true;

Expand Down Expand Up @@ -258,6 +263,10 @@ void DCE::markLive(SILFunction &F) {
}
continue;
}
if (auto *endAccess = dyn_cast<EndAccessInst>(&I)) {
addReverseDependency(endAccess->getBeginAccess(), &I);
continue;
}
if (seemsUseful(&I))
markValueLive(&I);
}
Expand Down
18 changes: 18 additions & 0 deletions test/SILOptimizer/dead_code_elimination.sil
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,21 @@ bb2:
bb3:
br bb1
}

// Check that DCE eliminates dead access instructions.
// CHECK-LABEL: sil @dead_access
// CHECK: bb0
// CHECK-NEXT: tuple
// CHECK-NEXT: return
// CHECK-LABEL: end sil function 'dead_access'
sil @dead_access : $@convention(thin) (@in Container) -> () {
bb0(%0 : $*Container):
%1 = begin_access [modify] [dynamic] %0 : $*Container
end_access %1 : $*Container

%3 = begin_access [read] [static] %0 : $*Container
end_access %3 : $*Container

%999 = tuple ()
return %999 : $()
}