Skip to content

Commit 8dd7676

Browse files
committed
SILCombine: handle mark_dependence in apply-of-partial_apply optimization
rdar://150686370
1 parent 84058a7 commit 8dd7676

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,8 +1520,14 @@ SILInstruction *SILCombiner::legacyVisitApplyInst(ApplyInst *AI) {
15201520
return nullptr;
15211521

15221522
SILValue callee = AI->getCallee();
1523-
if (auto *cee = dyn_cast<ConvertEscapeToNoEscapeInst>(callee)) {
1524-
callee = cee->getOperand();
1523+
for (;;) {
1524+
if (auto *cee = dyn_cast<ConvertEscapeToNoEscapeInst>(callee)) {
1525+
callee = cee->getOperand();
1526+
} else if (auto *mdi = dyn_cast<MarkDependenceInst>(callee)) {
1527+
callee = mdi->getValue();
1528+
} else {
1529+
break;
1530+
}
15251531
}
15261532
if (auto *CFI = dyn_cast<ConvertFunctionInst>(callee))
15271533
return optimizeApplyOfConvertFunctionInst(AI, CFI);

test/SILOptimizer/sil_combine_apply_ossa.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,22 @@ bb0(%0 : $Int):
11721172
return %r : $()
11731173
}
11741174

1175+
// CHECK-LABEL: sil [ossa] @test_mark_dependence_of_closure :
1176+
// CHECK-NOT: partial_apply
1177+
// CHECK-LABEL: } // end sil function 'test_mark_dependence_of_closure'
1178+
sil [ossa] @test_mark_dependence_of_closure : $@convention(thin) (Int) -> () {
1179+
bb0(%0 : $Int):
1180+
%3 = function_ref @closure2 : $@convention(thin) (Int) -> ()
1181+
%4 = partial_apply %3(%0) : $@convention(thin) (Int) -> ()
1182+
%5 = convert_function %4 to $@callee_owned () -> ()
1183+
%6 = convert_escape_to_noescape %5 to $@noescape @callee_owned () -> ()
1184+
%7 = mark_dependence %6 on %5
1185+
apply %7() : $@noescape @callee_owned () -> ()
1186+
destroy_value %5
1187+
%r = tuple ()
1188+
return %r : $()
1189+
}
1190+
11751191
sil [ossa] @closure2 : $@convention(thin) (Int) -> ()
11761192

11771193
sil [ossa] @yield1 : $@yield_once(Float) -> (@yields Float) {

0 commit comments

Comments
 (0)