Skip to content

Commit 2befdbe

Browse files
committed
SimplifyGlobalValue: handle fix_lifetime instruction
1 parent 25232e8 commit 2befdbe

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionPasses/SimplifyGlobalValue.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,20 @@ let simplifyGlobalValuePass = InstructionPass<GlobalValueInst>(
3737
private func checkUsers(of val: Value, users: inout Stack<Instruction>) -> Bool {
3838
for use in val.uses {
3939
let user = use.instruction
40-
if user is RefCountingInst || user is DebugValueInst {
41-
users.push(user)
42-
continue
43-
}
44-
if let upCast = user as? UpcastInst {
45-
if !checkUsers(of: upCast, users: &users) {
40+
switch user {
41+
case is RefCountingInst, is DebugValueInst, is FixLifetimeInst:
42+
users.push(user)
43+
case let upCast as UpcastInst:
44+
if !checkUsers(of: upCast, users: &users) {
45+
return false
46+
}
47+
case is RefElementAddrInst, is RefTailAddrInst:
48+
// Projection instructions don't access the object header, so they don't
49+
// prevent deleting reference counting instructions.
50+
break
51+
default:
4652
return false
47-
}
48-
continue
49-
}
50-
// Projection instructions don't access the object header, so they don't
51-
// prevent deleting reference counting instructions.
52-
if user is RefElementAddrInst || user is RefTailAddrInst {
53-
continue
5453
}
55-
return false
5654
}
5755
return true
5856
}

test/SILOptimizer/sil_combine_cow.sil renamed to test/SILOptimizer/sil_combine_inst_passes.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,26 @@ bb0:
104104
return %t : $(Builtin.Int1, Builtin.BridgeObject)
105105
}
106106

107+
sil_global private @outlined_global : $_ContiguousArrayStorage<Int>
108+
109+
// CHECK-LABEL: sil @remove_arc_of_global_value
110+
// CHECK-NOT: retain
111+
// CHECK-NOT: release
112+
// CHECK-NOT: fix_lifetime
113+
// CHECK-NOT: debug_value
114+
// CHECK: } // end sil function 'remove_arc_of_global_value'
115+
sil @remove_arc_of_global_value : $@convention(thin) () -> Int {
116+
bb0:
117+
%0 = global_value @outlined_global : $_ContiguousArrayStorage<Int>
118+
strong_retain %0 : $_ContiguousArrayStorage<Int>
119+
debug_value %0 : $_ContiguousArrayStorage<Int>, let, name "x"
120+
%2 = upcast %0 : $_ContiguousArrayStorage<Int> to $__ContiguousArrayStorageBase
121+
strong_retain %2 : $__ContiguousArrayStorageBase
122+
%13 = ref_tail_addr [immutable] %2 : $__ContiguousArrayStorageBase, $Int
123+
%16 = load %13 : $*Int
124+
fix_lifetime %0 : $_ContiguousArrayStorage<Int>
125+
strong_release %2 : $__ContiguousArrayStorageBase
126+
strong_release %0 : $_ContiguousArrayStorage<Int>
127+
return %16 : $Int
128+
}
129+

0 commit comments

Comments
 (0)