Skip to content

Commit 5c5cd9f

Browse files
committed
DeadObjectElimination: ignore begin_access and end_access instructions
Don't let access instructions prevent eliminating dead allocations #66496
1 parent 63808be commit 5c5cd9f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ static bool canZapInstruction(SILInstruction *Inst, bool acceptRefCountInsts,
280280
if (isa<InitExistentialAddrInst>(Inst))
281281
return true;
282282

283+
if (isa<BeginAccessInst>(Inst) || isa<EndAccessInst>(Inst))
284+
return true;
285+
283286
// If Inst does not read or write to memory, have side effects, and is not a
284287
// terminator, we can zap it.
285288
if (!Inst->mayHaveSideEffects() && !Inst->mayReadFromMemory() &&

test/SILOptimizer/dead_alloc_elim.sil

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ sil @store_to_trivial_property : $@convention(thin) (Int) -> () {
127127
bb0(%0 : $Int):
128128
%20 = alloc_ref [stack] $NontrivialDestructor
129129
%21 = ref_element_addr %20 : $NontrivialDestructor, #NontrivialDestructor.i
130-
store %0 to %21 : $*Int
130+
%22 = begin_access [modify] [dynamic] %21 : $*Int
131+
store %0 to %22 : $*Int
132+
end_access %22 : $*Int
131133
set_deallocating %20 : $NontrivialDestructor
132134
dealloc_ref %20 : $NontrivialDestructor
133135
dealloc_stack_ref %20 : $NontrivialDestructor

0 commit comments

Comments
 (0)