Skip to content

Commit 0bf643d

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 4590aa1 commit 0bf643d

File tree

3 files changed

+50
-32
lines changed

3 files changed

+50
-32
lines changed

Diff for: 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();

Diff for: test/SILOptimizer/dead_alloc.swift

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %target-swift-frontend -O -emit-sil -parse-as-library %s | %FileCheck %s
2+
3+
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
4+
// REQUIRES: swift_in_compiler
5+
6+
protocol E {
7+
func f() -> Bool
8+
}
9+
10+
protocol P {
11+
associatedtype A = Int
12+
}
13+
14+
public struct X : P, E {
15+
func f() -> Bool { return true }
16+
}
17+
18+
func g<T : P>(_ x : T) -> Bool {
19+
if let y = x as? E { return y.f() }
20+
return false
21+
}
22+
23+
// Check that this function can be completely constant folded and no alloc_stack remains.
24+
25+
// CHECK-LABEL: sil @$s10dead_alloc0A10AllocStackySbAA1XVF :
26+
// CHECK: bb0({{.*}}):
27+
// CHECK-NEXT: debug_value
28+
// CHECK-NEXT: integer_literal
29+
// CHECK-NEXT: struct
30+
// CHECK-NEXT: return
31+
// CHECK-NEXT: } // end sil function '$s10dead_alloc0A10AllocStackySbAA1XVF'
32+
public func deadAllocStack(_ x: X) -> Bool {
33+
return g(x)
34+
}
35+
36+
public class C<T> {
37+
let x: String = "123"
38+
}
39+
40+
// CHECK-LABEL: sil @$s10dead_alloc0A13ClassInstanceyyF :
41+
// CHECK: bb0:
42+
// CHECK-NEXT: tuple
43+
// CHECK-NEXT: return
44+
// CHECK-NEXT: } // end sil function '$s10dead_alloc0A13ClassInstanceyyF'
45+
public func deadClassInstance() {
46+
let _ = C<Int>()
47+
}

Diff for: test/SILOptimizer/dead_alloc_stack.swift

-32
This file was deleted.

0 commit comments

Comments
 (0)