Skip to content

Commit ca8536d

Browse files
authored
Merge pull request #78255 from meg-gupta/fixdcelc
[6.1] Look through borrowed from instructions before calling lifetime completion
2 parents 91c6425 + 7542581 commit ca8536d

File tree

2 files changed

+37
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)