Skip to content

Commit c421d4f

Browse files
authored
Merge pull request swiftlang#78209 from eeckstein/fix-copy-to-borrow-opt
CopyToBorrowOptimization: correctly handle uses in dead-end blocks when removing a copy_value
2 parents 5b98fe6 + bdd80aa commit c421d4f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/CopyToBorrowOptimization.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ private func optimize(copy: CopyValueInst, _ context: FunctionPassContext) {
9898
return
9999
}
100100

101-
var liverange = InstructionRange(begin: copy, ends: collectedUses.destroys, context)
101+
var liverange = InstructionRange(begin: copy, context)
102102
defer { liverange.deinitialize() }
103+
liverange.insert(contentsOf: collectedUses.destroys)
104+
liverange.insert(contentsOf: collectedUses.usersInDeadEndBlocks)
103105

104106
if !liverange.isFullyContainedIn(borrowScopeOf: copy.fromValue.lookThroughForwardingInstructions) {
105107
return

test/SILOptimizer/copy-to-borrow-optimization.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,3 +2106,16 @@ bb3:
21062106
return %0
21072107
}
21082108

2109+
// CHECK-LABEL: sil [ossa] @user_in_dead_end_block :
2110+
// CHECK: %2 = copy_value %1
2111+
// CHECK: } // end sil function 'user_in_dead_end_block'
2112+
sil [ossa] @user_in_dead_end_block : $@convention(thin) (@owned Klass) -> @owned Klass {
2113+
bb0(%0 : @owned $Klass):
2114+
%1 = begin_borrow %0
2115+
%2 = copy_value %1
2116+
end_borrow %1
2117+
%4 = function_ref @guaranteed_klass_user : $@convention(thin) (@guaranteed Klass) -> ()
2118+
%5 = apply %4(%2) : $@convention(thin) (@guaranteed Klass) -> ()
2119+
unreachable
2120+
}
2121+

0 commit comments

Comments
 (0)