Skip to content

Commit 0635bbb

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 df04e0e commit 0635bbb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,17 @@ class ExtendBoundaryToDestroys final {
743743
// before means it has multiple predecessors, so this must be \p block's
744744
// unique successor.
745745
assert(block->getSingleSuccessorBlock() == successor);
746+
// When this merge point was encountered the first time, a
747+
// destroy_value was sought from its top. If one was found, it was
748+
// added to the boundary. If no destroy_value was found, _that_ user
749+
// (i.e. the one on behalf of which extendBoundaryFromTerminator was
750+
// called which inserted successor into seenMergePoints) was added to
751+
// the boundary.
752+
//
753+
// This time, if a destroy was found, it's already in the boundary. If
754+
// no destroy was found, though, _this_ user must be added to the
755+
// boundary.
756+
foundDestroy = findDestroyFromBlockBegin(successor, currentDef);
746757
continue;
747758
}
748759
if (auto *dvi = findDestroyFromBlockBegin(successor, currentDef)) {

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)