DeadObjectElimination: handle the builtin "prepareInitialization"

which allows e.g. eliminating dead `Atomic` values
This commit is contained in:
Erik Eckstein
2025-08-01 14:55:42 +02:00
parent 3d6c240aa6
commit adc5d67a9a
2 changed files with 14 additions and 1 deletions

View File

@@ -318,7 +318,8 @@ static bool canZapInstruction(SILInstruction *Inst, bool acceptRefCountInsts,
// The value form of zero init is not a user of any operand. The address
// form however is easily zappable because it's always a trivial store.
if (auto bi = dyn_cast<BuiltinInst>(Inst)) {
if (bi->getBuiltinKind() == BuiltinValueKind::ZeroInitializer) {
if (bi->getBuiltinKind() == BuiltinValueKind::ZeroInitializer ||
bi->getBuiltinKind() == BuiltinValueKind::PrepareInitialization) {
return true;
}
}

View File

@@ -721,3 +721,15 @@ bb0:
%1 = tuple ()
return %1 : $()
}
// CHECK-LABEL: @dead_prepare_init
// CHECK-NOT: alloc_stack
// // CHECK: } // end sil function 'dead_prepare_init'
sil @dead_prepare_init : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $Kl
%empty = builtin "prepareInitialization"(%0 : $*Kl) : $()
dealloc_stack %0 : $*Kl
%1 = tuple ()
return %1 : $()
}