Skip to content

Commit 5c956f7

Browse files
committed
Review feedback; only rewrite access scopes when necessary
1 parent 7dea051 commit 5c956f7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceScopeFixup.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,20 @@ private func extendAccessScopes(dependence: LifetimeDependence, _ context: Funct
108108
private func extendAccessScope(beginAccess: BeginAccessInst, range: inout InstructionRange,
109109
_ context: FunctionPassContext) -> FunctionArgument? {
110110
var endAcceses = [Instruction]()
111-
// Collect the original end_access instructions and extend the range to to cover them. The access scope should only be
112-
// extended here; it may protect other memory operations.
111+
// Collect the original end_access instructions and extend the range to to cover them. The resulting access scope must
112+
// cover the original scope because it may protect other memory operations.
113+
var requiresExtension = false
113114
for end in beginAccess.endInstructions {
114115
endAcceses.append(end)
115-
range.insert(end)
116+
if range.contains(end) {
117+
// If any end_access is inside the new range, then all end_accesses must be rewritten.
118+
requiresExtension = true
119+
} else {
120+
range.insert(end)
121+
}
122+
}
123+
if !requiresExtension {
124+
return nil
116125
}
117126
assert(!range.ends.isEmpty)
118127

0 commit comments

Comments
 (0)