Skip to content

Commit 856afbb

Browse files
authored
Merge pull request #32836 from atrick/opt-escape-endaccess
Teach EscapeAnalysis to ignore end_access markers.
2 parents 07db05b + 3ff11aa commit 856afbb

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,10 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
20792079
return;
20802080
}
20812081

2082+
// Incidental uses produce no values and have no effect on their operands.
2083+
if (isIncidentalUse(I))
2084+
return;
2085+
20822086
// Instructions which return the address of non-writable memory cannot have
20832087
// an effect on escaping.
20842088
if (isNonWritableMemoryAddress(I))

test/SILOptimizer/escape_analysis.sil

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ bb0(%0 : $*SomeData):
19151915

19161916
// CHECK-LABEL: CG of testAccessMarker
19171917
// CHECK-NEXT: Arg %0 Esc: A, Succ: (%0.1)
1918-
// CHECK-NEXT: Con [ref] %0.1 Esc: G, Succ:
1918+
// CHECK-NEXT: Con [ref] %0.1 Esc: A, Succ:
19191919
// CHECK-LABEL: End
19201920
sil hidden @testAccessMarker : $@convention(thin) (@inout SomeData) -> () {
19211921
bb0(%0 : $*SomeData):
@@ -1927,6 +1927,34 @@ bb0(%0 : $*SomeData):
19271927
return %5 : $()
19281928
}
19291929

1930+
// Test that end_access does not cause its storage to escape.
1931+
//
1932+
// CHECK-LABEL: CG of testEndAccess
1933+
// CHECK: Val [ref] %0 Esc: , Succ: (%3)
1934+
// CHECK: Con [int] %3 Esc: , Succ: (%3.1)
1935+
// CHECK: Con [ref] %3.1 Esc: , Succ:
1936+
// CHECK: End
1937+
// CHECK: NoEscape: %0 = alloc_ref $IntWrapper
1938+
// CHECK: to set_deallocating %0 : $IntWrapper
1939+
// CHECK: NoEscape: %3 = ref_element_addr %0 : $IntWrapper, #IntWrapper.property
1940+
// CHECK: to set_deallocating %0 : $IntWrapper
1941+
// CHECK: MayEscape: %4 = begin_access [modify] [dynamic] [no_nested_conflict] %3 : $*Int64
1942+
// CHECK: to set_deallocating %0 : $IntWrapper
1943+
sil @testEndAccess : $@convention(thin) () -> () {
1944+
bb0:
1945+
%0 = alloc_ref $IntWrapper
1946+
%1 = integer_literal $Builtin.Int64, 0
1947+
%2 = struct $Int64 (%1 : $Builtin.Int64)
1948+
%3 = ref_element_addr %0 : $IntWrapper, #IntWrapper.property
1949+
%4 = begin_access [modify] [dynamic] [no_nested_conflict] %3 : $*Int64
1950+
store %2 to %4 : $*Int64
1951+
end_access %4 : $*Int64
1952+
set_deallocating %0 : $IntWrapper
1953+
dealloc_ref %0 : $IntWrapper
1954+
%9 = tuple ()
1955+
return %9 : $()
1956+
}
1957+
19301958
// -----------------------------------------------------------------------------
19311959
// Unreachable blocks are not mapped to the connection graph. Test
19321960
// that verification does not assert with "Missing escape connection

0 commit comments

Comments
 (0)