Skip to content

Commit 167d992

Browse files
committed
[LVA] Support access instructions in DCE.
Simple check for the following pattern: x = begin_access end_access x
1 parent dc122a3 commit 167d992

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ namespace {
4040
// FIXME: Reconcile the similarities between this and
4141
// isInstructionTriviallyDead.
4242
static bool seemsUseful(SILInstruction *I) {
43+
if (auto access = dyn_cast<BeginAccessInst>(I))
44+
return access->getSingleUse() == nullptr && !access->use_empty();
45+
46+
if (isa<EndAccessInst>(I))
47+
return I->getOperand(0)->getSingleUse() == nullptr;
48+
4349
if (I->mayHaveSideEffects())
4450
return true;
4551

test/SILOptimizer/dead_code_elimination.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,21 @@ bb2:
259259
bb3:
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+
}

0 commit comments

Comments
 (0)