Skip to content

Commit 7205e46

Browse files
committed
Disable -O copy propagation (lifetime shortening) by default
Problem: We continue to uncover code that assumes either precise local variable lifetimes (to the end of the lexical scope) or extended temporary lifetimes (to the end of the statement). These bugs require heroic debugging to find the root cause. Because they only show up in Release builds, they often manifest just before the affected project “ships” under an impending deadline. We now have enough information from projects that have been tested with copy propagation that we can both understand common patterns and identify some specific APIs that may cause trouble. We know what API annotations the compiler will need for helpful warnings and can begin adding those annotations. Disabling copy propagation now is only a temporary deferral, we will still need to bring it back by default. However, by then we should have: - LLDB and runtime support for debugging deinitialized objects - A variant of lifetime sortening that can run in Debug builds to catch problems before code ships - Static compiler warnings for likely invalid lifetime assumptions - Source annotations that allow those warnings to protect programmers against existing dangerous APIs In the meantime... Projects can experiment with the behavior and gradually migrate. Copy propagation will automatically be enabled in -enable-ossa-modules mode. It is important to work toward a single performance target. Supporting full OSSA and improving ARC performance without copy propagation would be prohibitively complicated. rdar://76438920 (Temporarily disable -O copy propagation by default)
1 parent 6c11713 commit 7205e46

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
477477
// Cleanup after SILGen: remove trivial copies to temporaries.
478478
P.addTempRValueOpt();
479479
// Cleanup after SILGen: remove unneeded borrows/copies.
480-
if (!P.getOptions().DisableCopyPropagation) {
480+
if (P.getOptions().EnableCopyPropagation) {
481481
P.addCopyPropagation();
482482
}
483483
P.addSemanticARCOpts();

test/Interpreter/builtin_bridge_object.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-run-simple-swift(-Onone -parse-stdlib -Xfrontend -enable-copy-propagation) | %FileCheck %s --check-prefixes=CHECK,CHECK-DBG
2-
// RUN: %target-run-simple-swift(-O -parse-stdlib) | %FileCheck --check-prefixes=CHECK,CHECK-OPT %s
2+
// RUN: %target-run-simple-swift(-O -parse-stdlib -Xfrontend -enable-copy-propagation) | %FileCheck --check-prefixes=CHECK,CHECK-OPT %s
33

44
// REQUIRES: executable_test
55
// REQUIRES: objc_interop

test/SILOptimizer/OSLogFullOptTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -emit-ir -swift-version 5 -O -primary-file %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
1+
// RUN: %target-swift-frontend -emit-ir -swift-version 5 -O -enable-copy-propagation -primary-file %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
22
//
33
// REQUIRES: VENDOR=apple
44
// REQUIRES: swift_stdlib_no_asserts

test/SILOptimizer/opt_remark/opt_remark_generator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-opt-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -emit-sil %s -o /dev/null -Xfrontend -verify
1+
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-opt-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify
22
// REQUIRES: optimized_stdlib,swift_stdlib_no_asserts
33

44
public class Klass {

test/SILOptimizer/opt_remark/opt_remark_generator_yaml.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-opt-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -emit-sil %s -o /dev/null -Xfrontend -verify
1+
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-opt-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify
22

33
// RUN: %empty-directory(%t)
4-
// RUN: %target-swiftc_driver -wmo -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -emit-sil -save-optimization-record=yaml -save-optimization-record-path %t/note.yaml %s -o /dev/null && %FileCheck --input-file=%t/note.yaml %s
4+
// RUN: %target-swiftc_driver -wmo -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil -save-optimization-record=yaml -save-optimization-record-path %t/note.yaml %s -o /dev/null && %FileCheck --input-file=%t/note.yaml %s
55

66
// REQUIRES: optimized_stdlib,swift_stdlib_no_asserts
77

test/SILOptimizer/outliner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -Osize -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked | %FileCheck %s
2-
// RUN: %target-swift-frontend -Osize -g -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked | %FileCheck %s
1+
// RUN: %target-swift-frontend -Osize -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation | %FileCheck %s
2+
// RUN: %target-swift-frontend -Osize -g -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation | %FileCheck %s
33

44
// REQUIRES: objc_interop
55
// REQUIRES: optimized_stdlib

0 commit comments

Comments
 (0)