Skip to content

Commit ce64630

Browse files
committed
Enable the CopyPropagation pass.
For now simply run the pass before SemanticARCOpts. This will probably be called as a utility from within SemanticARCOpts so it can be iteratively applied after other ARC-related transformations.
1 parent 392014b commit ce64630

File tree

7 files changed

+409
-104
lines changed

7 files changed

+409
-104
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ void addFunctionPasses(SILPassPipelinePlan &P,
304304

305305
// We earlier eliminated ownership if we are not compiling the stdlib. Now
306306
// handle the stdlib functions, re-simplifying, eliminating ARC as we do.
307+
P.addCopyPropagation();
307308
P.addSemanticARCOpts();
308309
P.addNonTransparentFunctionOwnershipModelEliminator();
309310

@@ -447,6 +448,7 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
447448
// Cleanup after SILGen: remove trivial copies to temporaries.
448449
P.addTempRValueOpt();
449450
// Cleanup after SILGen: remove unneeded borrows/copies.
451+
P.addCopyPropagation();
450452
P.addSemanticARCOpts();
451453

452454
// Devirtualizes differentiability witnesses into functions that reference them.

stdlib/public/core/StringObject.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ extension _StringObject {
207207
internal init(
208208
object: AnyObject, discriminator: UInt64, countAndFlags: CountAndFlags
209209
) {
210+
defer { _fixLifetime(object) }
210211
let builtinRawObject: Builtin.Int64 = Builtin.reinterpretCast(object)
211212
let builtinDiscrim: Builtin.Int64 = discriminator._value
212213
self.init(

test/SILOptimizer/OSLogFullOptTest.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func testNSObjectInterpolation(nsArray: NSArray) {
140140
// CHECK: [[NOT_ENABLED]]:
141141
// CHECK-NEXT: tail call void @swift_release
142142
// CHECK-NEXT: tail call void @llvm.objc.release
143+
// CHECK-NEXT: tail call void @llvm.objc.release
143144
// CHECK-NEXT: br label %[[EXIT:[0-9]+]]
144145

145146
// CHECK: [[ENABLED]]:
@@ -170,7 +171,7 @@ func testNSObjectInterpolation(nsArray: NSArray) {
170171
// CHECK-NEXT: [[BITCASTED_SRC2:%.+]] = bitcast i8* [[NSARRAY_ARG]] to %TSo7NSArrayC*
171172
// CHECK-64-NEXT: store %TSo7NSArrayC* [[BITCASTED_SRC2]], %TSo7NSArrayC** [[BITCASTED_DEST2]], align 8
172173
// CHECK-32-NEXT: store %TSo7NSArrayC* [[BITCASTED_SRC2]], %TSo7NSArrayC** [[BITCASTED_DEST2]], align 4
173-
174+
// CHECK-NEXT: tail call void @llvm.objc.release
174175
// CHECK-64-NEXT: tail call swiftcc void @"${{.*}}_os_log_impl_test{{.*}}"({{.*}}, {{.*}}, {{.*}}, {{.*}}, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @{{.*}}, i64 0, i64 0), i8* {{(nonnull )?}}[[BUFFER]], i32 12)
175176
// CHECK-32-NEXT: tail call swiftcc void @"${{.*}}_os_log_impl_test{{.*}}"({{.*}}, {{.*}}, {{.*}}, {{.*}}, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @{{.*}}, i32 0, i32 0), i8* {{(nonnull )?}}[[BUFFER]], i32 8)
176177
// CHECK-NEXT: [[BITCASTED_OBJ_STORAGE:%.+]] = bitcast i8* [[OBJ_STORAGE]] to %swift.opaque*
@@ -181,7 +182,6 @@ func testNSObjectInterpolation(nsArray: NSArray) {
181182
// CHECK-NEXT: br label %[[EXIT]]
182183

183184
// CHECK: [[EXIT]]:
184-
// CHECK-NEXT: tail call void @llvm.objc.release(i8* [[NSARRAY_ARG]])
185185
// CHECK-NEXT: ret void
186186
}
187187

@@ -349,7 +349,6 @@ func testMetatypeInterpolation<T>(of type: T.Type) {
349349

350350
// CHECK: [[NOT_ENABLED]]:
351351
// CHECK-NEXT: call void @swift_release
352-
// CHECK-NEXT: br label %[[EXIT:[0-9]+]]
353352

354353
// CHECK: [[ENABLED]]:
355354
//

0 commit comments

Comments
 (0)