Skip to content

Commit adc5d67

Browse files
committed
DeadObjectElimination: handle the builtin "prepareInitialization"
which allows e.g. eliminating dead `Atomic` values
1 parent 3d6c240 commit adc5d67

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ static bool canZapInstruction(SILInstruction *Inst, bool acceptRefCountInsts,
318318
// The value form of zero init is not a user of any operand. The address
319319
// form however is easily zappable because it's always a trivial store.
320320
if (auto bi = dyn_cast<BuiltinInst>(Inst)) {
321-
if (bi->getBuiltinKind() == BuiltinValueKind::ZeroInitializer) {
321+
if (bi->getBuiltinKind() == BuiltinValueKind::ZeroInitializer ||
322+
bi->getBuiltinKind() == BuiltinValueKind::PrepareInitialization) {
322323
return true;
323324
}
324325
}

test/SILOptimizer/dead_alloc_elim.sil

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,15 @@ bb0:
721721
%1 = tuple ()
722722
return %1 : $()
723723
}
724+
725+
// CHECK-LABEL: @dead_prepare_init
726+
// CHECK-NOT: alloc_stack
727+
// // CHECK: } // end sil function 'dead_prepare_init'
728+
sil @dead_prepare_init : $@convention(thin) () -> () {
729+
bb0:
730+
%0 = alloc_stack $Kl
731+
%empty = builtin "prepareInitialization"(%0 : $*Kl) : $()
732+
dealloc_stack %0 : $*Kl
733+
%1 = tuple ()
734+
return %1 : $()
735+
}

0 commit comments

Comments
 (0)