Skip to content

Commit cf71957

Browse files
committed
Look through borrowed from instructions before calling lifetime completion
Lifetime completion will insert end_borrows only on borrow introducers. Look through "borrowed from" instructions before calling it. rdar://141490551
1 parent 8353a8c commit cf71957

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ void DCE::endLifetimeOfLiveValue(Operand *op, SILInstruction *insertPt) {
637637
// If DCE is going to delete the block in which we have to insert a
638638
// compensating lifetime end, let complete lifetimes utility handle it.
639639
if (!LiveBlocks.contains(insertPt->getParent())) {
640-
valuesToComplete.push_back(value);
640+
valuesToComplete.push_back(lookThroughBorrowedFromDef(value));
641641
return;
642642
}
643643

test/SILOptimizer/dead_code_elimination_nontrivial_ossa.sil

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,3 +1376,38 @@ bb3:
13761376
%res = tuple ()
13771377
return %res : $()
13781378
}
1379+
1380+
// Ensure no verification error
1381+
sil [ossa] @dce_borrowedfromuser : $@convention(thin) (@guaranteed FakeOptional<Klass>) -> () {
1382+
bb0(%0 : @guaranteed $FakeOptional<Klass>):
1383+
%1 = copy_value %0
1384+
%2 = begin_borrow %1
1385+
%3 = begin_borrow %1
1386+
br bb1(%2, %3)
1387+
1388+
bb1(%5 : @reborrow $FakeOptional<Klass>, %6 : @reborrow $FakeOptional<Klass>):
1389+
%7 = borrowed %6 from (%1)
1390+
%8 = borrowed %5 from (%1)
1391+
switch_enum %7, case #FakeOptional.some!enumelt: bb2, case #FakeOptional.none!enumelt: bb3
1392+
1393+
bb2(%10 : @guaranteed $Klass):
1394+
%11 = function_ref @$use_klass2 : $@convention(thin) (@guaranteed Klass) -> ()
1395+
%12 = apply %11(%10) : $@convention(thin) (@guaranteed Klass) -> ()
1396+
br bb4
1397+
1398+
bb3:
1399+
br bb4
1400+
1401+
bb4:
1402+
br bb5(%8, %7)
1403+
1404+
bb5(%16 : @reborrow $FakeOptional<Klass>, %17 : @reborrow $FakeOptional<Klass>):
1405+
%18 = borrowed %17 from (%1)
1406+
%19 = borrowed %16 from (%1)
1407+
end_borrow %19
1408+
end_borrow %18
1409+
destroy_value %1
1410+
%23 = tuple ()
1411+
return %23
1412+
}
1413+

0 commit comments

Comments
 (0)