Skip to content

Commit 7956ff2

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 7956ff2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import Swift
44
import Builtin
55

6+
// REQUIRES: swift_in_compiler
7+
68
// CHECK-LABEL: sil @test_enum_with_initialize :
79
// CHECK: bb0(%0 : $*Optional<Any>, %1 : $*Any):
810
// CHECK-NEXT: [[E:%[0-9]+]] = init_enum_data_addr %0
@@ -249,3 +251,20 @@ bb0(%0 : $*T, %1 : $*T):
249251
return %78 : $()
250252
}
251253

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

0 commit comments

Comments
 (0)