Skip to content

EscapeAnalysis: fix a wrong use-point detection. #8577

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
Apr 6, 2017
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
13 changes: 10 additions & 3 deletions lib/SILOptimizer/Analysis/EscapeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1818,9 +1818,16 @@ bool EscapeAnalysis::canObjectOrContentEscapeTo(SILValue V, FullApplySite FAS) {
if (ConGraph->isUsePoint(UsePoint, Node))
return true;

if (hasReferenceSemantics(V->getType())) {
// Check if the object "content", i.e. a pointer to one of its stored
// properties, can escape to the called function.
if (isPointer(V)) {
// Check if the object "content" can escape to the called function.
// This will catch cases where V is a reference and a pointer to a stored
// property escapes.
// It's also important in case of a pointer assignment, e.g.
// V = V1
// apply(V1)
// In this case the apply is only a use-point for V1 and V1's content node.
// As V1's content node is the same as V's content node, we also make the
// check for the content node.
CGNode *ContentNode = ConGraph->getContentNode(Node);
if (ContentNode->escapesInsideFunction(false))
return true;
Expand Down
24 changes: 24 additions & 0 deletions test/SILOptimizer/redundant_load_elim.sil
Original file line number Diff line number Diff line change
Expand Up @@ -1166,3 +1166,27 @@ bb0(%0 : $Builtin.RawPointer):
return %6 : $Int
}

sil @overwrite_int : $@convention(thin) (@inout Int, Int) -> ()

// CHECK-LABEL: sil @test_address_block_args
// CHECK: bb2({{.*}}):
// CHECK: apply
// CHECK: [[L:%.*]] = load
// CHECK: return [[L]]
sil @test_address_block_args : $@convention(thin) (Int) -> Int {
bb0(%0 : $Int):
%4 = alloc_stack $Int
store %0 to %4 : $*Int
cond_br undef, bb1(%4 : $*Int), bb2(%4 : $*Int)

bb1(%a1 : $*Int):
br bb2(%a1 : $*Int)

bb2(%a : $*Int):
%l1 = load %a : $*Int
%60 = function_ref @overwrite_int : $@convention(thin) (@inout Int, Int) -> ()
%61 = apply %60(%4, %l1) : $@convention(thin) (@inout Int, Int) -> ()
%r = load %a : $*Int
dealloc_stack %4 : $*Int
return %r : $Int
}