Skip to content

Commit 0371043

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 0371043

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

+3
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

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,26 @@ func g<T : P>(_ x : T) -> Bool {
1919

2020
// Check that this function can be completely constant folded and no alloc_stack remains.
2121

22-
// CHECK-LABEL: sil @$s16dead_alloc_stack6testitySbAA1XVF
22+
// CHECK-LABEL: sil @$s10dead_alloc0A10AllocStackySbAA1XVF :
2323
// CHECK: bb0({{.*}}):
2424
// CHECK-NEXT: debug_value
2525
// CHECK-NEXT: integer_literal
2626
// CHECK-NEXT: struct
2727
// CHECK-NEXT: return
28-
// CHECK-NEXT: } // end sil function '$s16dead_alloc_stack6testitySbAA1XVF'
29-
public func testit(_ x: X) -> Bool {
28+
// CHECK-NEXT: } // end sil function '$s10dead_alloc0A10AllocStackySbAA1XVF'
29+
public func deadAllocStack(_ x: X) -> Bool {
3030
return g(x)
3131
}
3232

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

0 commit comments

Comments
 (0)