Skip to content

Fix LICM for begin_access/end_access in OSSA #79025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/SILOptimizer/LoopTransforms/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,10 @@ void LoopTreeOptimization::analyzeCurrentLoop(
for (auto &Inst : *BB) {
if (hasOwnershipOperandsOrResults(&Inst)) {
checkSideEffects(Inst, sideEffects, sideEffectsInBlock);
// Collect fullApplies to be checked in analyzeBeginAccess
if (auto fullApply = FullApplySite::isa(&Inst)) {
fullApplies.push_back(fullApply);
}
continue;
}
switch (Inst.getKind()) {
Expand Down
33 changes: 33 additions & 0 deletions test/SILOptimizer/licm.sil
Original file line number Diff line number Diff line change
Expand Up @@ -1606,3 +1606,36 @@ bb3:
return %r : $()
}

sil @foo : $@convention(thin) (@guaranteed { var Int }) -> ()

// CHECK-LABEL: sil [ossa] @test_begin_access : $@convention(thin) (Int) -> () {
// CHECK: bb2:
// CHECK: begin_access
// CHECK: end_access
// CHECK: bb3
// CHECK-LABEL: } // end sil function 'test_begin_access'
sil [ossa] @test_begin_access : $@convention(thin) (Int) -> () {
bb0(%0 : $Int):
%1 = alloc_box ${ var Int }, var, name "now"
%2 = begin_borrow [lexical] [var_decl] %1
%3 = project_box %2, 0
store %0 to [trivial] %3
br bb2

bb1:
br bb2

bb2:
%7 = function_ref @foo : $@convention(thin) (@guaranteed { var Int }) -> ()
%8 = apply %7(%2) : $@convention(thin) (@guaranteed { var Int }) -> ()
%9 = begin_access [modify] [dynamic] %3
store %0 to [trivial] %9
end_access %9
cond_br undef, bb3, bb1

bb3:
end_borrow %2
destroy_value %1
%15 = tuple ()
return %15
}