Skip to content

Commit 73f0d8e

Browse files
authored
Merge pull request swiftlang#39775 from nate-chandler/ownership/used-dagnodeworklist-in-visittransitiveendborrows
Used DAGNodeWorklist in visitTransitiveEndBorrows.
2 parents 4bdef1b + 51fd5f4 commit 73f0d8e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,11 @@ void swift::findTransitiveReborrowBaseValuePairs(
14381438
void swift::visitTransitiveEndBorrows(
14391439
BorrowedValue beginBorrow,
14401440
function_ref<void(EndBorrowInst *)> visitEndBorrow) {
1441-
SmallSetVector<SILValue, 4> worklist;
1441+
DAGNodeWorklist<SILValue, 4> worklist;
14421442
worklist.insert(beginBorrow.value);
14431443

14441444
while (!worklist.empty()) {
1445-
auto val = worklist.pop_back_val();
1445+
auto val = worklist.pop();
14461446
for (auto *consumingUse : val->getConsumingUses()) {
14471447
auto *consumingUser = consumingUse->getUser();
14481448
if (auto *branch = dyn_cast<BranchInst>(consumingUser)) {

test/SILOptimizer/dead_code_elimination_nontrivial_ossa.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,3 +652,30 @@ bb4(%3 : @owned $Klass):
652652
return %res : $()
653653
}
654654

655+
// CHECK-LABEL: sil [ossa] @looping_borrow : $@convention(thin) () -> () {
656+
// CHECK-NOT: destroy_value
657+
// CHECK-LABEL: } // end sil function 'looping_borrow'
658+
sil [ossa] @looping_borrow : $@convention(thin) () -> () {
659+
entry:
660+
%instance_1 = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
661+
%lifetime_1 = begin_borrow [lexical] %instance_1 : $FakeOptional<Klass>
662+
br loop_entry(%instance_1 : $FakeOptional<Klass>, %lifetime_1 : $FakeOptional<Klass>)
663+
664+
loop_entry(%18 : @owned $FakeOptional<Klass>, %19 : @guaranteed $FakeOptional<Klass>):
665+
br loop_body
666+
667+
loop_body:
668+
cond_br undef, loop_back, loop_exit
669+
670+
loop_back:
671+
br loop_entry(%18 : $FakeOptional<Klass>, %19 : $FakeOptional<Klass>)
672+
673+
loop_exit:
674+
end_borrow %19 : $FakeOptional<Klass>
675+
destroy_value %18 : $FakeOptional<Klass>
676+
br exit
677+
678+
exit:
679+
%retval = tuple ()
680+
return %retval : $()
681+
}

0 commit comments

Comments
 (0)