Skip to content

Commit d1a75e7

Browse files
committed
LifetimeDependenceScopeFixup: handle non-dominated dependent uses.
1 parent 1122cc4 commit d1a75e7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceScopeFixup.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,31 @@ let lifetimeDependenceScopeFixupPass = FunctionPass(
4646
}
4747
}
4848

49-
// Extend all access scopes that enclose `dependence`. If dependence is on an access scope in the caller, then return
50-
// the function argument that represents the dependence scope.
49+
/// Extend all access scopes that enclose `dependence`. If dependence is on an access scope in the caller, then return
50+
/// the function argument that represents the dependence scope.
5151
private func extendAccessScopes(dependence: LifetimeDependence, _ context: FunctionPassContext) -> FunctionArgument? {
5252
log("Scope fixup for lifetime dependent instructions: \(dependence)")
5353

5454
guard case .access(let bai) = dependence.scope else {
5555
return nil
5656
}
57+
let function = bai.parentFunction
5758
var range = InstructionRange(begin: bai, context)
58-
var walker = LifetimeDependenceScopeFixupWalker(bai.parentFunction, context) {
59+
var walker = LifetimeDependenceScopeFixupWalker(function, context) {
5960
range.insert($0.instruction)
6061
return .continueWalk
6162
}
6263
defer {walker.deinitialize()}
6364
_ = walker.walkDown(root: dependence.dependentValue)
6465
defer {range.deinitialize()}
6566

67+
// Lifetime dependenent uses may no be dominated by the access. The dependent value may be used by a phi or stored
68+
// into a memory location. The access may be conditional relative to such uses. If this is the case, then the
69+
// instruction range must include the function entry.
70+
let firstInst = function.entryBlock.instructions.first!
71+
if firstInst != bai, range.contains(firstInst) {
72+
return nil
73+
}
6674
if let arg = extendAccessScope(beginAccess: bai, range: &range, context) {
6775
// If the dependent value is returned, then return the FunctionArgument that it depends on.
6876
return walker.dependsOnCaller ? arg : nil

0 commit comments

Comments
 (0)