Skip to content

Commit 40d5e7a

Browse files
authored
Merge pull request swiftlang#21649 from eeckstein/add-dse-pass
SILOptimizer: add an earlier DeadStoreElimination pass to fix a phase ordering problem
2 parents 47b987f + 130f162 commit 40d5e7a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ static bool addMidLevelPassPipeline(SILPassPipelinePlan &P,
415415
static void addClosureSpecializePassPipeline(SILPassPipelinePlan &P) {
416416
P.startPipeline("ClosureSpecialize");
417417
P.addDeadFunctionElimination();
418+
P.addDeadStoreElimination();
418419
P.addDeadObjectElimination();
419420

420421
// These few passes are needed to cleanup between loop unrolling and GlobalOpt.

test/SILOptimizer/globalopt_let_propagation.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let S = "String1"
1616
let VOLUME1 = I * J
1717
let VOLUME2 = J * 2
1818
let VOLUME3 = I + 10
19-
19+
let maxSize = Int.max >> 1
2020

2121

2222
struct IntWrapper1 {
@@ -74,6 +74,8 @@ struct B {
7474

7575
static let VOLUME3 = I + 10
7676

77+
static let maxSize = Int.max >> 1
78+
7779
static var PROP1: Double {
7880
return PI
7981
}
@@ -110,6 +112,8 @@ class C {
110112
static let VOLUME2 = J * 2
111113

112114
static let VOLUME3 = I + 10
115+
116+
static let maxSize = Int.max >> 1
113117

114118
static var PROP1: Double {
115119
return PI
@@ -172,7 +176,7 @@ public func test_let_double_complex() -> Double {
172176
// CHECK: return
173177
@inline(never)
174178
public func test_let_int_complex() -> Int {
175-
return I + J + VOLUME1 + VOLUME2 + VOLUME3 + PROP2
179+
return I + J + VOLUME1 + VOLUME2 + VOLUME3 + PROP2 + maxSize
176180
}
177181

178182
// CHECK-LABEL: sil [noinline] @$s25globalopt_let_propagation019test_static_struct_B7_doubleSdyF
@@ -218,10 +222,9 @@ public func test_static_struct_let_double_complex() -> Double {
218222
// CHECK: return
219223
@inline(never)
220224
public func test_static_struct_let_int_complex() -> Int {
221-
return B.I + B.J + B.VOLUME1 + B.VOLUME2 + B.VOLUME3 + B.PROP2
225+
return B.I + B.J + B.VOLUME1 + B.VOLUME2 + B.VOLUME3 + B.maxSize + B.PROP2
222226
}
223227

224-
225228
// CHECK-LABEL: sil [noinline] @$s25globalopt_let_propagation018test_static_class_B7_doubleSdyF
226229
// CHECK: bb0:
227230
// CHECK-NEXT: float_literal
@@ -265,7 +268,7 @@ public func test_static_class_let_double_complex() -> Double {
265268
// CHECK: return
266269
@inline(never)
267270
public func test_static_class_let_int_complex() -> Int {
268-
return C.I + C.J + C.VOLUME1 + C.VOLUME2 + C.VOLUME3 + C.PROP2
271+
return C.I + C.J + C.VOLUME1 + C.VOLUME2 + C.VOLUME3 + C.maxSize + C.PROP2
269272
}
270273

271274
// CHECK-LABEL: sil [noinline] @$s25globalopt_let_propagation15test_var_doubleSdyF

0 commit comments

Comments
 (0)