Skip to content

[opt] Move "LastRelease" outside BB iteration. #31137

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 3 additions & 5 deletions lib/SILOptimizer/Transforms/ReleaseDevirtualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ void ReleaseDevirtualizer::run() {
SILFunction *F = getFunction();
RCIA = PM->getAnalysis<RCIdentityAnalysis>()->get(F);

// The last release_value or strong_release instruction before the
// deallocation.
SILInstruction *LastRelease = nullptr;
bool Changed = false;
for (SILBasicBlock &BB : *F) {

// The last release_value or strong_release instruction before the
// deallocation.
SILInstruction *LastRelease = nullptr;

for (SILInstruction &I : BB) {
if (LastRelease) {
if (auto *DRI = dyn_cast<DeallocRefInst>(&I)) {
Expand Down
21 changes: 21 additions & 0 deletions test/SILOptimizer/devirt_release.sil
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ bb0:
return %r : $()
}

// CHECK-LABEL: sil @devirtualize_release_multiblock
// CHECK-NOT: strong_release
// CHECK: [[A:%[0-9]+]] = alloc_ref
// CHECK-NEXT: set_deallocating [[A]]
// CHECK: [[D:%[0-9]+]] = function_ref @$s4test1BCfD
// CHECK-NEXT: apply [[D]]([[A]])
// CHECK-NEXT: br
// CHECK: bb1:
// CHECK-NEXT: dealloc_ref [stack] [[A]]
// CHECK: return
sil @devirtualize_release_multiblock : $@convention(thin) () -> () {
bb0:
%1 = alloc_ref [stack] $B
strong_release %1 : $B
br bb1

bb1:
dealloc_ref [stack] %1 : $B
%r = tuple ()
return %r : $()
}

sil @unknown_func : $@convention(thin) () -> ()

Expand Down