Skip to content

Commit fcd4542

Browse files
committed
Optimizer: register explicit-copy instruction simplifications for SILCombine
Usually `explicit_copy_addr` and `explicit_copy_value` don't survive until the first SILCombine pass run anyway. But if they do, the simplifications need to be registered, otherwise SILCombine will complain.
1 parent cb238d7 commit fcd4542

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ private func registerSwiftPasses() {
115115
registerForSILCombine(BeginBorrowInst.self, { run(BeginBorrowInst.self, $0) })
116116
registerForSILCombine(BeginCOWMutationInst.self, { run(BeginCOWMutationInst.self, $0) })
117117
registerForSILCombine(BuiltinInst.self, { run(BuiltinInst.self, $0) })
118+
registerForSILCombine(ExplicitCopyAddrInst.self, { run(ExplicitCopyAddrInst.self, $0) })
119+
registerForSILCombine(ExplicitCopyValueInst.self,{ run(ExplicitCopyValueInst.self, $0) })
118120
registerForSILCombine(FixLifetimeInst.self, { run(FixLifetimeInst.self, $0) })
119121
registerForSILCombine(GlobalValueInst.self, { run(GlobalValueInst.self, $0) })
120122
registerForSILCombine(StructInst.self, { run(StructInst.self, $0) })

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5544,3 +5544,37 @@ entry(%e_addr : $*NoncopyableEnum):
55445544
end_borrow %i : $CopyableStruct
55455545
return undef : $()
55465546
}
5547+
5548+
// CHECK-LABEL: sil [ossa] @simplify_copy_take_init :
5549+
// CHECK: {{ }}copy_addr [take] %1 to [init] %0
5550+
// CHECK-NEXT: %3 = tuple ()
5551+
// CHECK: } // end sil function 'simplify_copy_take_init'
5552+
sil [ossa] @simplify_copy_take_init : $@convention(thin) (@in String) -> @out String {
5553+
bb0(%0 : $*String, %1 : $*String):
5554+
explicit_copy_addr [take] %1 to [init] %0
5555+
%3 = tuple ()
5556+
return %3
5557+
}
5558+
5559+
// CHECK-LABEL: sil [ossa] @simplify_copy_assign :
5560+
// CHECK: {{ }}copy_addr %1 to %0
5561+
// CHECK-NEXT: %3 = tuple ()
5562+
// CHECK: } // end sil function 'simplify_copy_assign'
5563+
sil [ossa] @simplify_copy_assign : $@convention(thin) (@inout String, @inout String) -> () {
5564+
bb0(%0 : $*String, %1 : $*String):
5565+
explicit_copy_addr %1 to %0
5566+
%3 = tuple ()
5567+
return %3
5568+
}
5569+
5570+
// CHECK-LABEL: sil [ossa] @simplify_explicit_copy_value :
5571+
// CHECK: %1 = copy_value %0
5572+
// CHECK-NEXT: return %1
5573+
// CHECK: } // end sil function 'simplify_explicit_copy_value'
5574+
sil [ossa] @simplify_explicit_copy_value : $@convention(thin) (@guaranteed String) -> @owned String {
5575+
bb0(%0 : @guaranteed $String):
5576+
%1 = explicit_copy_value %0
5577+
return %1
5578+
}
5579+
5580+

0 commit comments

Comments
 (0)