Skip to content

Commit d9fc62e

Browse files
committed
SimplifyKeyPath: remove dead keypath instructions also in non-OSSA
which means: handle of strong_release instructions
1 parent dfba6e2 commit d9fc62e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyKeyPath.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fileprivate func allUsesRemovable(instruction: Instruction) -> Bool {
3434
switch use.instruction {
3535
case is UpcastInst,
3636
is DestroyValueInst,
37+
is StrongReleaseInst,
3738
is BeginBorrowInst,
3839
is EndBorrowInst,
3940
is MoveValueInst,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=keypath | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
8+
struct S {
9+
@_hasStorage var a: Int
10+
@_hasStorage var b: Int
11+
}
12+
13+
// CHECK-LABEL: sil [ossa] @remove_dead_keypath_ossa :
14+
// CHECK-NOT: keypath
15+
// CHECK-NOT: destroy_value
16+
// CHECK: %0 = tuple
17+
// CHECK-NEXT: return
18+
// CHECK: } // end sil function 'remove_dead_keypath_ossa'
19+
sil [ossa] @remove_dead_keypath_ossa : $@convention(thin) () -> () {
20+
bb0:
21+
%0 = keypath $WritableKeyPath<S, Int>, (root $S; stored_property #S.b : $Int)
22+
%1 = upcast %0 : $WritableKeyPath<S, Int> to $KeyPath<S, Int>
23+
%2 = begin_borrow %1 : $KeyPath<S, Int>
24+
end_borrow %2 : $KeyPath<S, Int>
25+
%4 = copy_value %1 : $KeyPath<S, Int>
26+
%5 = move_value %4 : $KeyPath<S, Int>
27+
destroy_value %1 : $KeyPath<S, Int>
28+
destroy_value %5 : $KeyPath<S, Int>
29+
%r = tuple()
30+
return %r : $()
31+
}
32+
33+
// CHECK-LABEL: sil @remove_dead_keypath :
34+
// CHECK-NOT: keypath
35+
// CHECK-NOT: strong_release
36+
// CHECK: %0 = tuple
37+
// CHECK-NEXT: return
38+
// CHECK: } // end sil function 'remove_dead_keypath'
39+
sil @remove_dead_keypath : $@convention(thin) () -> () {
40+
bb0:
41+
%0 = keypath $WritableKeyPath<S, Int>, (root $S; stored_property #S.b : $Int)
42+
%1 = upcast %0 : $WritableKeyPath<S, Int> to $KeyPath<S, Int>
43+
strong_release %1 : $KeyPath<S, Int>
44+
%r = tuple()
45+
return %r : $()
46+
}
47+

0 commit comments

Comments
 (0)