Skip to content

Commit 3644d98

Browse files
Merge pull request #64400 from nate-chandler/copy-propagation/run-side-effect-analysis-first
CopyPropagation: Compute side-effects first.
2 parents 1f3623d + ade29db commit 3644d98

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
594594
P.addTempRValueOpt();
595595
// Cleanup after SILGen: remove unneeded borrows/copies.
596596
if (P.getOptions().CopyPropagation == CopyPropagationOption::On) {
597+
P.addComputeSideEffects();
597598
P.addCopyPropagation();
598599
}
599600
P.addSemanticARCOpts();

lib/SILOptimizer/Transforms/CopyPropagation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
/// TODO: Cleanup the resulting SIL by deleting instructions that produce dead
3636
/// values (after removing its copies).
3737
///
38+
/// PASS DEPENDENCIES:
39+
/// - ComputeSideEffects
40+
///
41+
/// ANALYSES USED:
42+
/// - BasicCalleeAnalysis
43+
/// - DeadEndBlocksAnalysis
44+
/// - DominanceAnalysis
45+
/// - NonLocalAccessBlockAnalysis
46+
/// - PostOrderAnalysis
47+
///
3848
/// ===----------------------------------------------------------------------===
3949

4050
#define DEBUG_TYPE "copy-propagation"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-swift-frontend -primary-file %s -O -sil-verify-all -module-name=test -emit-sil | %FileCheck %s
2+
3+
// REQUIRES: swift_in_compiler
4+
5+
class C {}
6+
7+
@_silgen_name("non_barrier")
8+
@inline(never)
9+
func non_barrier() {}
10+
11+
@_silgen_name("borrow")
12+
@inline(never)
13+
func borrow(_ c: C)
14+
15+
// CHECK-LABEL: sil {{.*}}@test_hoist_over_non_barrier : {{.*}} {
16+
// CHECK: [[INSTANCE:%[^,]+]] = alloc_ref
17+
// CHECK: [[BORROW:%[^,]+]] = function_ref @borrow
18+
// CHECK: apply [[BORROW]]([[INSTANCE]])
19+
// CHECK: strong_release [[INSTANCE]]
20+
// CHECK: [[NON_BARRIER:%[^,]+]] = function_ref @non_barrier
21+
// CHECK: apply [[NON_BARRIER]]()
22+
// CHECK-LABEL: } // end sil function 'test_hoist_over_non_barrier'
23+
@_silgen_name("test_hoist_over_non_barrier")
24+
func test_hoist_over_non_barrier() {
25+
let c = C()
26+
borrow(c)
27+
non_barrier()
28+
}
29+

0 commit comments

Comments
 (0)