Skip to content

[5.6] AllocStackHoisting: fix the check for availability-checks #40761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/IRGen/AllocStackHoisting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,12 @@ class HoistAllocStack {
} // end anonymous namespace

bool indicatesDynamicAvailabilityCheckUse(SILInstruction *I) {
auto *Apply = dyn_cast<ApplyInst>(I);
if (!Apply)
return false;
if (Apply->hasSemantics(semantics::AVAILABILITY_OSVERSION))
return true;
auto *FunRef = Apply->getReferencedFunctionOrNull();
if (!FunRef)
return false;
if (auto *Apply = dyn_cast<ApplyInst>(I)) {
return Apply->hasSemantics(semantics::AVAILABILITY_OSVERSION);
}
if (auto *bi = dyn_cast<BuiltinInst>(I)) {
return bi->getBuiltinInfo().ID == BuiltinValueKind::TargetOSVersionAtLeast;
}
return false;
}

Expand Down
27 changes: 27 additions & 0 deletions test/SILOptimizer/allocstack_hoisting.sil
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,30 @@ bb3:
%3 = builtin "int_trap"() : $()
unreachable
}

// CHECK-LABEL: sil @dont_hoist_with_availability_checks
// CHECK-NOT: alloc_stack
// CHECK: cond_br
// CHECK: bb1:
// CHECK: alloc_stack
// CHECK: } // end sil function 'dont_hoist_with_availability_checks'
sil @dont_hoist_with_availability_checks : $@convention(thin) <T> (@in T, Builtin.Int1) -> () {
bb0(%0 : $*T, %1: $Builtin.Int1):
%5 = integer_literal $Builtin.Int32, 15
%7 = builtin "targetOSVersionAtLeast"(%5 : $Builtin.Int32, %5 : $Builtin.Int32, %5 : $Builtin.Int32) : $Builtin.Int32
%8 = builtin "cmp_eq_Int32"(%7 : $Builtin.Int32, %5 : $Builtin.Int32) : $Builtin.Int1
cond_br %8, bb1, bb2
bb1:
%2 = alloc_stack $T
copy_addr [take] %0 to [initialization] %2 : $*T
destroy_addr %2 : $*T
dealloc_stack %2 : $*T
br bb3
bb2:
destroy_addr %0 : $*T
br bb3
bb3:
%3 = tuple ()
return %3 : $()
}