Skip to content

Commit 22c1f89

Browse files
committed
[opt] Move "LastRelease" outside BB iteration.
This means that "LastRelease" can be tracked through multiple basic blocks.
1 parent dc122a3 commit 22c1f89

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lib/SILOptimizer/Transforms/ReleaseDevirtualizer.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,11 @@ void ReleaseDevirtualizer::run() {
7070
SILFunction *F = getFunction();
7171
RCIA = PM->getAnalysis<RCIdentityAnalysis>()->get(F);
7272

73+
// The last release_value or strong_release instruction before the
74+
// deallocation.
75+
SILInstruction *LastRelease = nullptr;
7376
bool Changed = false;
7477
for (SILBasicBlock &BB : *F) {
75-
76-
// The last release_value or strong_release instruction before the
77-
// deallocation.
78-
SILInstruction *LastRelease = nullptr;
79-
8078
for (SILInstruction &I : BB) {
8179
if (LastRelease) {
8280
if (auto *DRI = dyn_cast<DeallocRefInst>(&I)) {

test/SILOptimizer/devirt_release.sil

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,27 @@ bb0:
9393
return %r : $()
9494
}
9595

96+
// CHECK-LABEL: sil @devirtualize_release_multiblock
97+
// CHECK-NOT: strong_release
98+
// CHECK: [[A:%[0-9]+]] = alloc_ref
99+
// CHECK-NEXT: set_deallocating [[A]]
100+
// CHECK: [[D:%[0-9]+]] = function_ref @$s4test1BCfD
101+
// CHECK-NEXT: apply [[D]]([[A]])
102+
// CHECK-NEXT: br
103+
// CHECK: bb1:
104+
// CHECK-NEXT: dealloc_ref [stack] [[A]]
105+
// CHECK: return
106+
sil @devirtualize_release_multiblock : $@convention(thin) () -> () {
107+
bb0:
108+
%1 = alloc_ref [stack] $B
109+
strong_release %1 : $B
110+
br bb1
111+
112+
bb1:
113+
dealloc_ref [stack] %1 : $B
114+
%r = tuple ()
115+
return %r : $()
116+
}
96117

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

0 commit comments

Comments
 (0)