Skip to content

Commit e23234e

Browse files
committed
Fix DestroyHoisting: don't ignore pointer escapes.
A pointer escape means the liveness is incomplete. Don't hoist destroys with incomplete liveness.
1 parent ec6f9b5 commit e23234e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DestroyHoisting.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ private func optimize(value: Value, _ context: FunctionPassContext) {
9191
var hoistableDestroys = selectHoistableDestroys(of: value, context)
9292
defer { hoistableDestroys.deinitialize() }
9393

94-
var minimalLiverange = InstructionRange(withLiverangeOf: value, ignoring: hoistableDestroys, context)
94+
guard var minimalLiverange = InstructionRange(withLiverangeOf: value, ignoring: hoistableDestroys, context) else {
95+
return
96+
}
9597
defer { minimalLiverange.deinitialize() }
9698

9799
hoistDestroys(of: value, toEndOf: minimalLiverange, restrictingTo: &hoistableDestroys, context)
@@ -177,10 +179,10 @@ private func removeDestroys(
177179

178180
private extension InstructionRange {
179181

180-
init(withLiverangeOf initialDef: Value, ignoring ignoreDestroys: InstructionSet, _ context: FunctionPassContext)
182+
init?(withLiverangeOf initialDef: Value, ignoring ignoreDestroys: InstructionSet, _ context: FunctionPassContext)
181183
{
182184
var liverange = InstructionRange(for: initialDef, context)
183-
var visitor = InteriorUseWalker(definingValue: initialDef, ignoreEscape: true, visitInnerUses: true, context) {
185+
var visitor = InteriorUseWalker(definingValue: initialDef, ignoreEscape: false, visitInnerUses: true, context) {
184186
if !ignoreDestroys.contains($0.instruction) {
185187
liverange.insert($0.instruction)
186188
}
@@ -197,7 +199,9 @@ private extension InstructionRange {
197199
return .continueWalk
198200
}
199201

200-
_ = visitor.visitUses()
202+
guard visitor.visitUses() == .continueWalk else {
203+
return nil
204+
}
201205
self = liverange
202206
}
203207

0 commit comments

Comments
 (0)