Skip to content

Commit b97582b

Browse files
authored
Merge pull request swiftlang#79025 from meg-gupta/licmossa
Fix LICM for begin_access/end_access in OSSA
2 parents 997eab4 + 6a47193 commit b97582b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/SILOptimizer/LoopTransforms/LICM.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,10 @@ void LoopTreeOptimization::analyzeCurrentLoop(
890890
for (auto &Inst : *BB) {
891891
if (hasOwnershipOperandsOrResults(&Inst)) {
892892
checkSideEffects(Inst, sideEffects, sideEffectsInBlock);
893+
// Collect fullApplies to be checked in analyzeBeginAccess
894+
if (auto fullApply = FullApplySite::isa(&Inst)) {
895+
fullApplies.push_back(fullApply);
896+
}
893897
continue;
894898
}
895899
switch (Inst.getKind()) {

test/SILOptimizer/licm.sil

+33
Original file line numberDiff line numberDiff line change
@@ -1606,3 +1606,36 @@ bb3:
16061606
return %r : $()
16071607
}
16081608

1609+
sil @foo : $@convention(thin) (@guaranteed { var Int }) -> ()
1610+
1611+
// CHECK-LABEL: sil [ossa] @test_begin_access : $@convention(thin) (Int) -> () {
1612+
// CHECK: bb2:
1613+
// CHECK: begin_access
1614+
// CHECK: end_access
1615+
// CHECK: bb3
1616+
// CHECK-LABEL: } // end sil function 'test_begin_access'
1617+
sil [ossa] @test_begin_access : $@convention(thin) (Int) -> () {
1618+
bb0(%0 : $Int):
1619+
%1 = alloc_box ${ var Int }, var, name "now"
1620+
%2 = begin_borrow [lexical] [var_decl] %1
1621+
%3 = project_box %2, 0
1622+
store %0 to [trivial] %3
1623+
br bb2
1624+
1625+
bb1:
1626+
br bb2
1627+
1628+
bb2:
1629+
%7 = function_ref @foo : $@convention(thin) (@guaranteed { var Int }) -> ()
1630+
%8 = apply %7(%2) : $@convention(thin) (@guaranteed { var Int }) -> ()
1631+
%9 = begin_access [modify] [dynamic] %3
1632+
store %0 to [trivial] %9
1633+
end_access %9
1634+
cond_br undef, bb3, bb1
1635+
1636+
bb3:
1637+
end_borrow %2
1638+
destroy_value %1
1639+
%15 = tuple ()
1640+
return %15
1641+
}

0 commit comments

Comments
 (0)