Skip to content

Commit d19be45

Browse files
committed
[AliasAnalysis] Builtin effects depend on escaping
Mostly restore the behavior of getMemoryEffectsFn on builtins other than `once` and `onceWithContext` to before 8a8a895 but keeping the improvement to return `Instruction.memoryEffects` in the face of escaping.
1 parent 6cdab78 commit d19be45

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Analysis/AliasAnalysis.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ private func getMemoryEffect(ofBuiltin builtin: BuiltinInst, for address: Value,
159159
let callee = builtin.operands[1].value
160160
return context.calleeAnalysis.getSideEffects(ofCallee: callee).memory
161161
default:
162-
return builtin.memoryEffects
162+
if address.at(path).isEscaping(using: EscapesToInstructionVisitor(target: builtin, isAddress: true), context) {
163+
return builtin.memoryEffects
164+
}
165+
return SideEffects.Memory()
163166
}
164167
}
165168

test/SILOptimizer/templvalueopt.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,20 @@ bb0(%0 : $*T, %1 : $*T):
249249
return %78 : $()
250250
}
251251

252+
253+
// CHECK-LABEL: sil @optimize_builtin_zeroInitialize : {{.*}} {
254+
// CHECK: bb0([[RET_ADDR:%[^,]+]] :
255+
// CHECK: builtin "zeroInitializer"<T>([[RET_ADDR]] : $*T) : $()
256+
// CHECK: apply undef<T>([[RET_ADDR]])
257+
// CHECK-LABEL: } // end sil function 'optimize_builtin_zeroInitialize'
258+
sil @optimize_builtin_zeroInitialize : $@convention(thin) <T> () -> @out T {
259+
bb0(%ret_addr : $*T):
260+
%temporary = alloc_stack [lexical] $T
261+
builtin "zeroInitializer"<T>(%temporary : $*T) : $()
262+
apply undef<T>(%temporary) : $@convention(thin) <T> () -> @out T
263+
copy_addr [take] %temporary to [init] %ret_addr : $*T
264+
dealloc_stack %temporary : $*T
265+
%15 = tuple ()
266+
return %15 : $()
267+
}
268+

0 commit comments

Comments
 (0)