Skip to content

Commit 665fdca

Browse files
committed
Optimizer: add an additional DeadObjectElimination at the end of the pipeline
The last dead-store-elimination pass can expose opportunities for dead object elimination. rdar://110846405
1 parent 79616c4 commit 665fdca

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,9 @@ static void addLowLevelPassPipeline(SILPassPipelinePlan &P) {
760760
P.addObjectOutliner();
761761
P.addDeadStoreElimination();
762762

763+
// dead-store-elimination can expose opportunities for dead object elimination.
764+
P.addDeadObjectElimination();
765+
763766
// We've done a lot of optimizations on this function, attempt to FSO.
764767
P.addFunctionSignatureOpts();
765768
P.addComputeEscapeEffects();

test/SILOptimizer/dead_alloc_stack.swift renamed to test/SILOptimizer/dead_alloc.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-swift-frontend -O -emit-sil -parse-as-library %s | %FileCheck %s
22

3+
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
4+
35
protocol E {
46
func f() -> Bool
57
}
@@ -19,14 +21,26 @@ func g<T : P>(_ x : T) -> Bool {
1921

2022
// Check that this function can be completely constant folded and no alloc_stack remains.
2123

22-
// CHECK-LABEL: sil @$s16dead_alloc_stack6testitySbAA1XVF
24+
// CHECK-LABEL: sil @$s10dead_alloc0A10AllocStackySbAA1XVF :
2325
// CHECK: bb0({{.*}}):
2426
// CHECK-NEXT: debug_value
2527
// CHECK-NEXT: integer_literal
2628
// CHECK-NEXT: struct
2729
// CHECK-NEXT: return
28-
// CHECK-NEXT: } // end sil function '$s16dead_alloc_stack6testitySbAA1XVF'
29-
public func testit(_ x: X) -> Bool {
30+
// CHECK-NEXT: } // end sil function '$s10dead_alloc0A10AllocStackySbAA1XVF'
31+
public func deadAllocStack(_ x: X) -> Bool {
3032
return g(x)
3133
}
3234

35+
public class C<T> {
36+
let x: String = "123"
37+
}
38+
39+
// CHECK-LABEL: sil @$s10dead_alloc0A13ClassInstanceyyF :
40+
// CHECK: bb0:
41+
// CHECK-NEXT: tuple
42+
// CHECK-NEXT: return
43+
// CHECK-NEXT: } // end sil function '$s10dead_alloc0A13ClassInstanceyyF'
44+
public func deadClassInstance() {
45+
let _ = C<Int>()
46+
}

0 commit comments

Comments
 (0)