Skip to content

Commit f88d7eb

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 875a2dc + 8c03ace commit f88d7eb

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

lib/IRGen/AllocStackHoisting.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,16 @@ class HoistAllocStack {
427427
};
428428
} // end anonymous namespace
429429

430-
bool indicatesDynamicAvailabilityCheckUse(SILInstruction *I) {
430+
bool inhibitsAllocStackHoisting(SILInstruction *I) {
431431
if (auto *Apply = dyn_cast<ApplyInst>(I)) {
432432
return Apply->hasSemantics(semantics::AVAILABILITY_OSVERSION);
433433
}
434434
if (auto *bi = dyn_cast<BuiltinInst>(I)) {
435435
return bi->getBuiltinInfo().ID == BuiltinValueKind::TargetOSVersionAtLeast;
436436
}
437+
if (isa<HasSymbolInst>(I)) {
438+
return true;
439+
}
437440
return false;
438441
}
439442

@@ -453,8 +456,10 @@ void HoistAllocStack::collectHoistableInstructions() {
453456
FunctionExits.push_back(Term);
454457
continue;
455458
}
456-
// Don't perform alloc_stack hoisting in functions with availability.
457-
if (indicatesDynamicAvailabilityCheckUse(&Inst)) {
459+
// Don't perform alloc_stack hoisting in functions containing
460+
// instructions that indicate hoisting may be unsafe (e.g. `if
461+
// #available(...)` or `if #_hasSymbol(...)`.
462+
if (inhibitsAllocStackHoisting(&Inst)) {
458463
AllocStackToHoist.clear();
459464
return;
460465
}

test/SILOptimizer/allocstack_hoisting.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,26 @@ bb3:
257257
return %3 : $()
258258
}
259259

260+
// CHECK-LABEL: sil @dont_hoist_with_has_symbol_checks
261+
// CHECK-NOT: alloc_stack
262+
// CHECK: cond_br
263+
// CHECK: bb1:
264+
// CHECK: alloc_stack
265+
// CHECK: } // end sil function 'dont_hoist_with_has_symbol_checks'
266+
sil @dont_hoist_with_has_symbol_checks : $@convention(thin) <T> (@in T, Builtin.Int1) -> () {
267+
bb0(%0 : $*T, %1: $Builtin.Int1):
268+
%5 = has_symbol #FixedSize.init
269+
cond_br %5, bb1, bb2
270+
bb1:
271+
%2 = alloc_stack $T
272+
copy_addr [take] %0 to [init] %2 : $*T
273+
destroy_addr %2 : $*T
274+
dealloc_stack %2 : $*T
275+
br bb3
276+
bb2:
277+
destroy_addr %0 : $*T
278+
br bb3
279+
bb3:
280+
%3 = tuple ()
281+
return %3 : $()
282+
}

0 commit comments

Comments
 (0)