Skip to content

Commit 38febd6

Browse files
authored
Merge pull request #40761 from eeckstein/fix-alloc-stack-hoisting-5.6
[5.6] AllocStackHoisting: fix the check for availability-checks
2 parents 8ae983c + f5712ce commit 38febd6

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

lib/IRGen/AllocStackHoisting.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,12 @@ class HoistAllocStack {
348348
} // end anonymous namespace
349349

350350
bool indicatesDynamicAvailabilityCheckUse(SILInstruction *I) {
351-
auto *Apply = dyn_cast<ApplyInst>(I);
352-
if (!Apply)
353-
return false;
354-
if (Apply->hasSemantics(semantics::AVAILABILITY_OSVERSION))
355-
return true;
356-
auto *FunRef = Apply->getReferencedFunctionOrNull();
357-
if (!FunRef)
358-
return false;
351+
if (auto *Apply = dyn_cast<ApplyInst>(I)) {
352+
return Apply->hasSemantics(semantics::AVAILABILITY_OSVERSION);
353+
}
354+
if (auto *bi = dyn_cast<BuiltinInst>(I)) {
355+
return bi->getBuiltinInfo().ID == BuiltinValueKind::TargetOSVersionAtLeast;
356+
}
359357
return false;
360358
}
361359

test/SILOptimizer/allocstack_hoisting.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,30 @@ bb3:
230230
%3 = builtin "int_trap"() : $()
231231
unreachable
232232
}
233+
234+
// CHECK-LABEL: sil @dont_hoist_with_availability_checks
235+
// CHECK-NOT: alloc_stack
236+
// CHECK: cond_br
237+
// CHECK: bb1:
238+
// CHECK: alloc_stack
239+
// CHECK: } // end sil function 'dont_hoist_with_availability_checks'
240+
sil @dont_hoist_with_availability_checks : $@convention(thin) <T> (@in T, Builtin.Int1) -> () {
241+
bb0(%0 : $*T, %1: $Builtin.Int1):
242+
%5 = integer_literal $Builtin.Int32, 15
243+
%7 = builtin "targetOSVersionAtLeast"(%5 : $Builtin.Int32, %5 : $Builtin.Int32, %5 : $Builtin.Int32) : $Builtin.Int32
244+
%8 = builtin "cmp_eq_Int32"(%7 : $Builtin.Int32, %5 : $Builtin.Int32) : $Builtin.Int1
245+
cond_br %8, bb1, bb2
246+
bb1:
247+
%2 = alloc_stack $T
248+
copy_addr [take] %0 to [initialization] %2 : $*T
249+
destroy_addr %2 : $*T
250+
dealloc_stack %2 : $*T
251+
br bb3
252+
bb2:
253+
destroy_addr %0 : $*T
254+
br bb3
255+
bb3:
256+
%3 = tuple ()
257+
return %3 : $()
258+
}
259+

0 commit comments

Comments
 (0)