Skip to content

Commit d866158

Browse files
committed
SILCombine: handle begin_borrow in the partial_apply -> apply peephole optimization
1 parent 6d0903a commit d866158

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/SILOptimizer/Utils/PartialApplyCombiner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ bool PartialApplyCombiner::combine() {
240240
auto *user = use->getUser();
241241

242242
// Recurse through copy_value
243-
if (auto *cvi = dyn_cast<CopyValueInst>(user)) {
244-
for (auto *copyUse : cvi->getUses())
243+
if (isa<CopyValueInst>(user) || isa<BeginBorrowInst>(user)) {
244+
for (auto *copyUse : cast<SingleValueInstruction>(user)->getUses())
245245
worklist.push_back(copyUse);
246246
continue;
247247
}

test/SILOptimizer/sil_combine_apply_ossa.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,3 +1152,22 @@ bb3:
11521152
%rv = tuple()
11531153
return %rv : $()
11541154
}
1155+
1156+
// CHECK-LABEL: sil [ossa] @test_copy_and_borrow_of_closure
1157+
// CHECK-NOT: partial_apply
1158+
// CHECK-LABEL: } // end sil function 'test_copy_and_borrow_of_closure'
1159+
sil [ossa] @test_copy_and_borrow_of_closure : $@convention(thin) (Int) -> () {
1160+
bb0(%0 : $Int):
1161+
%3 = function_ref @closure2 : $@convention(thin) (Int) -> ()
1162+
%5 = partial_apply %3(%0) : $@convention(thin) (Int) -> ()
1163+
%6 = begin_borrow [lexical] %5 : $@callee_owned () -> ()
1164+
%7 = copy_value %6 : $@callee_owned () -> ()
1165+
apply %7() : $@callee_owned () -> ()
1166+
end_borrow %6 : $@callee_owned () -> ()
1167+
destroy_value %5 : $@callee_owned () -> ()
1168+
%r = tuple ()
1169+
return %r : $()
1170+
}
1171+
1172+
sil [ossa] @closure2 : $@convention(thin) (Int) -> ()
1173+

0 commit comments

Comments
 (0)