Skip to content

Commit f88ca51

Browse files
committed
[CanonOSSALifetime] Fixed term boundary extension.
If multiple terminators which branch to the same merge block are added to the boundary, depending on whether a destroy_value can be found within the block either (a) every terminator must be added to the boundary or (b) the destroy_value must be added to the boundary exactly once.
1 parent 1e4086f commit f88ca51

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,18 @@ class ExtendBoundaryToDestroys final {
764764
// before means it has multiple predecessors, so this must be \p block's
765765
// unique successor.
766766
assert(block->getSingleSuccessorBlock() == successor);
767+
// When this merge point was encountered the first time, a
768+
// destroy_value was sought from its top. If one was found, it was
769+
// added to the boundary. If no destroy_value was found, _that_ user
770+
// (i.e. the one on behalf of which extendBoundaryFromTerminator was
771+
// called which inserted successor into seenMergePoints) was added to
772+
// the boundary.
773+
//
774+
// This time, if a destroy was found, it's already in the boundary. If
775+
// no destroy was found, though, _this_ user must be added to the
776+
// boundary.
777+
foundDestroy =
778+
findDestroyFromBlockBegin(successor, currentDef, isDestroy);
767779
continue;
768780
}
769781
if (auto *dvi =

test/SILOptimizer/canonicalize_ossa_lifetime_unit.sil

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-sil-opt -unit-test-runner %s -o /dev/null 2>&1 | %FileCheck %s
22

33
class C {}
4+
sil @getOwned : $@convention(thin) () -> @owned C
45

56
// When access scopes are respected, the lifetime which previously extended
67
// beyond the access scope still extends beyond it.
@@ -45,3 +46,31 @@ bb0(%addr : $*C):
4546
%retval = tuple ()
4647
return %retval : $()
4748
}
49+
50+
51+
// CHECK-LABEL: begin running test 1 of 1 on reuse_destroy_after_barrier_phi: canonicalize-ossa-lifetime with: true, false, true, @trace
52+
// CHECK-LABEL: sil [ossa] @reuse_destroy_after_barrier_phi : {{.*}} {
53+
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
54+
// CHECK: {{bb[0-9]+}}({{%[^,]+}}
55+
// CHECK: destroy_value [[INSTANCE]]
56+
// CHECK-LABEL: } // end sil function 'reuse_destroy_after_barrier_phi'
57+
// CHECK-LABEL: end running test 1 of 1 on reuse_destroy_after_barrier_phi: canonicalize-ossa-lifetime with: true, false, true, @trace
58+
sil [ossa] @reuse_destroy_after_barrier_phi : $@convention(thin) (@owned C) -> @owned C {
59+
entry(%instance : @owned $C):
60+
debug_value [trace] %instance : $C
61+
test_specification "canonicalize-ossa-lifetime true false true @trace"
62+
%get = function_ref @getOwned : $@convention(thin) () -> @owned C
63+
cond_br undef, through, loop
64+
65+
through:
66+
%4 = copy_value %instance : $C
67+
br exit(%4 : $C)
68+
69+
loop:
70+
%other = apply %get() : $@convention(thin) () -> @owned C
71+
br exit(%other : $C)
72+
73+
exit(%out : @owned $C):
74+
destroy_value %instance : $C
75+
return %out : $C
76+
}

0 commit comments

Comments
 (0)