Skip to content

Commit fd4e2ab

Browse files
committed
Optimizer: replace the MandatoryGenericSpecializer with the MandatoryPerformanceOptimizations in the pipeline
1 parent 2d0ee16 commit fd4e2ab

File tree

4 files changed

+90
-57
lines changed

4 files changed

+90
-57
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
218218
}
219219

220220
P.addOptimizeHopToExecutor();
221-
P.addMandatoryGenericSpecializer();
222221

222+
// These diagnostic passes must run before OnoneSimplification because
223+
// they rely on completely unoptimized SIL.
223224
P.addDiagnoseUnreachable();
224225
P.addDiagnoseInfiniteRecursion();
225226
P.addYieldOnceCheck();
@@ -231,18 +232,18 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
231232
P.addDiagnoseLifetimeIssues();
232233
}
233234

234-
P.addOnoneSimplification();
235-
P.addInitializeStaticGlobals();
236-
237-
P.addPerformanceDiagnostics();
238-
239235
// Canonical swift requires all non cond_br critical edges to be split.
240236
P.addSplitNonCondBrCriticalEdges();
241237

242238
// As a temporary measure, we also eliminate move only for non-trivial types
243239
// until we can audit the later part of the pipeline. Eventually, this should
244240
// occur before IRGen.
245241
P.addMoveOnlyTypeEliminator();
242+
243+
P.addMandatoryPerformanceOptimizations();
244+
P.addOnoneSimplification();
245+
P.addInitializeStaticGlobals();
246+
P.addPerformanceDiagnostics();
246247
}
247248

248249
SILPassPipelinePlan

test/SILOptimizer/cast_folding.swift

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,10 @@ func test18_2() -> Bool {
527527

528528

529529
// CHECK-LABEL: sil hidden [noinline] @$s12cast_folding6test19SbyF : $@convention(thin) () -> Bool
530-
// CHECK: bb0
531-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, -1
532-
// CHECK-NEXT: %1 = struct $Bool
533-
// CHECK-NEXT: return %1
530+
// CHECK: [[I1:%.*]] = integer_literal $Builtin.Int1, -1
531+
// CHECK: [[B:%.*]] = struct $Bool ([[I1]]
532+
// CHECK: return [[B]]
533+
// CHECK: } // end sil function '$s12cast_folding6test19SbyF'
534534
@inline(never)
535535
func test19() -> Bool {
536536
let t: Any.Type = type(of: 1 as Any)
@@ -595,10 +595,10 @@ func test22_2() -> Bool {
595595
}
596596

597597
// CHECK-LABEL: sil hidden [noinline] @$s12cast_folding6test23SbyF : $@convention(thin) () -> Bool
598-
// CHECK: bb0
599-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, 0
600-
// CHECK-NEXT: %1 = struct $Bool
601-
// CHECK-NEXT: return %1
598+
// CHECK: [[I0:%.*]] = integer_literal $Builtin.Int1, 0
599+
// CHECK: [[B:%.*]] = struct $Bool ([[I0]]
600+
// CHECK: return [[B]]
601+
// CHECK: } // end sil function '$s12cast_folding6test23SbyF'
602602
@inline(never)
603603
func test23() -> Bool {
604604
return cast23(P.self)
@@ -626,10 +626,10 @@ func test24_2() -> Bool {
626626

627627

628628
// CHECK-LABEL: sil hidden [noinline] @$s12cast_folding6test25SbyF : $@convention(thin) () -> Bool
629-
// CHECK: bb0
630-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, 0
631-
// CHECK-NEXT: %1 = struct $Bool
632-
// CHECK-NEXT: return %1
629+
// CHECK: [[I0:%.*]] = integer_literal $Builtin.Int1, 0
630+
// CHECK: [[B:%.*]] = struct $Bool ([[I0]]
631+
// CHECK: return [[B]]
632+
// CHECK: } // end sil function '$s12cast_folding6test25SbyF'
633633
@inline(never)
634634
func test25() -> Bool {
635635
return cast25(P.self)
@@ -647,10 +647,10 @@ func test26() -> Bool {
647647

648648

649649
// CHECK-LABEL: sil hidden [noinline] @$s12cast_folding6test27SbyF
650-
// CHECK: bb0
651-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, 0
652-
// CHECK-NEXT: %1 = struct $Bool
653-
// CHECK-NEXT: return %1
650+
// CHECK: [[I0:%.*]] = integer_literal $Builtin.Int1, 0
651+
// CHECK: [[B:%.*]] = struct $Bool ([[I0]]
652+
// CHECK: return [[B]]
653+
// CHECK: } // end sil function '$s12cast_folding6test27SbyF'
654654
@inline(never)
655655
func test27() -> Bool {
656656
return cast27(D.self)
@@ -955,61 +955,61 @@ public func test42(_ p: P) -> Bool {
955955
return cast42(p)
956956
}
957957

958-
// CHECK-LABEL: sil [noinline] @{{.*}}test43{{.*}}
959-
// CHECK: bb0
960-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, -1
961-
// CHECK-NEXT: %1 = struct $Bool
962-
// CHECK-NEXT: return %1
958+
// CHECK-LABEL: sil [noinline] @$s12cast_folding6test43SbyF
959+
// CHECK: [[I1:%.*]] = integer_literal $Builtin.Int1, -1
960+
// CHECK: [[B:%.*]] = struct $Bool ([[I1]]
961+
// CHECK: return [[B]]
962+
// CHECK: } // end sil function '$s12cast_folding6test43SbyF'
963963
@inline(never)
964964
public func test43() -> Bool {
965965
return P.self is Any.Type
966966
}
967967

968-
// CHECK-LABEL: sil [noinline] @{{.*}}test44{{.*}}
969-
// CHECK: bb0
970-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, -1
971-
// CHECK-NEXT: %1 = struct $Bool
972-
// CHECK-NEXT: return %1
968+
// CHECK-LABEL: sil [noinline] @$s12cast_folding6test44SbyF
969+
// CHECK: [[I1:%.*]] = integer_literal $Builtin.Int1, -1
970+
// CHECK: [[B:%.*]] = struct $Bool ([[I1]]
971+
// CHECK: return [[B]]
972+
// CHECK: } // end sil function '$s12cast_folding6test44SbyF'
973973
@inline(never)
974974
public func test44() -> Bool {
975975
return Any.self is Any.Type
976976
}
977977

978-
// CHECK-LABEL: sil [noinline] @{{.*}}test45{{.*}}
979-
// CHECK: bb0
980-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, -1
981-
// CHECK-NEXT: %1 = struct $Bool
982-
// CHECK-NEXT: return %1
978+
// CHECK-LABEL: sil [noinline] @$s12cast_folding6test45SbyF
979+
// CHECK: [[I1:%.*]] = integer_literal $Builtin.Int1, -1
980+
// CHECK: [[B:%.*]] = struct $Bool ([[I1]]
981+
// CHECK: return [[B]]
982+
// CHECK: } // end sil function '$s12cast_folding6test45SbyF'
983983
@inline(never)
984984
public func test45() -> Bool {
985985
return (P & R).self is Any.Type
986986
}
987987

988-
// CHECK-LABEL: sil [noinline] @{{.*}}test46{{.*}}
989-
// CHECK: bb0
990-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, -1
991-
// CHECK-NEXT: %1 = struct $Bool
992-
// CHECK-NEXT: return %1
988+
// CHECK-LABEL: sil [noinline] @$s12cast_folding6test46SbyF
989+
// CHECK: [[I1:%.*]] = integer_literal $Builtin.Int1, -1
990+
// CHECK: [[B:%.*]] = struct $Bool ([[I1]]
991+
// CHECK: return [[B]]
992+
// CHECK: } // end sil function '$s12cast_folding6test46SbyF'
993993
@inline(never)
994994
public func test46() -> Bool {
995995
return AnyObject.self is Any.Type
996996
}
997997

998-
// CHECK-LABEL: sil [noinline] @{{.*}}test47{{.*}}
999-
// CHECK: bb0
1000-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, -1
1001-
// CHECK-NEXT: %1 = struct $Bool
1002-
// CHECK-NEXT: return %1
998+
// CHECK-LABEL: sil [noinline] @$s12cast_folding6test47SbyF
999+
// CHECK: [[I1:%.*]] = integer_literal $Builtin.Int1, -1
1000+
// CHECK: [[B:%.*]] = struct $Bool ([[I1]]
1001+
// CHECK: return [[B]]
1002+
// CHECK: } // end sil function '$s12cast_folding6test47SbyF'
10031003
@inline(never)
10041004
public func test47() -> Bool {
10051005
return Any.Type.self is Any.Type
10061006
}
10071007

1008-
// CHECK-LABEL: sil [noinline] @{{.*}}test48{{.*}}
1009-
// CHECK: bb0
1010-
// CHECK-NEXT: %0 = integer_literal $Builtin.Int1, 0
1011-
// CHECK-NEXT: %1 = struct $Bool
1012-
// CHECK-NEXT: return %1
1008+
// CHECK-LABEL: sil [noinline] @$s12cast_folding6test48SbyF
1009+
// CHECK: [[I0:%.*]] = integer_literal $Builtin.Int1, 0
1010+
// CHECK: [[B:%.*]] = struct $Bool ([[I0]]
1011+
// CHECK: return [[B]]
1012+
// CHECK: } // end sil function '$s12cast_folding6test48SbyF'
10131013
@inline(never)
10141014
public func test48() -> Bool {
10151015
return Any.Type.self is Any.Type.Type
@@ -1027,10 +1027,10 @@ public func testCastAnyObjectProtocolToAnyObjectType() -> AnyObject.Type? {
10271027
return cast(AnyObject.self)
10281028
}
10291029

1030-
// CHECK-LABEL: // testCastProtocolTypeProtocolToProtocolTypeType
1031-
// CHECK: sil [noinline] @{{.*}}testCastProtocol{{.*}}$@convention(thin) () -> Optional<@thick any P.Type.Type>
1032-
// CHECK: %0 = enum $Optional{{.*}}, #Optional.none!enumelt
1033-
// CHECK-NEXT: return %0
1030+
// CHECK-LABEL: sil [noinline] @$s12cast_folding020testCastProtocolTypee2ToefF0AA1P_pXpXpSgyF :
1031+
// CHECK: [[E:%.*]] = enum $Optional{{.*}}, #Optional.none!enumelt
1032+
// CHECK: return [[E]]
1033+
// CHECK: } // end sil function '$s12cast_folding020testCastProtocolTypee2ToefF0AA1P_pXpXpSgyF'
10341034
@inline(never)
10351035
public func testCastProtocolTypeProtocolToProtocolTypeType() -> P.Type.Type? {
10361036
return P.Type.self as? P.Type.Type

test/SILOptimizer/globalopt_global_propagation.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-swift-frontend -parse-as-library -O -emit-sil %s | %FileCheck %s
2-
// RUN: %target-swift-frontend -parse-as-library -O -wmo -emit-sil %s | %FileCheck -check-prefix=CHECK-WMO %s
32

43
// REQUIRES: swift_in_compiler
54

test/SILOptimizer/performance-annotations.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,36 @@ struct Buffer {
239239
}
240240
}
241241

242+
@_noLocks
243+
func testBitShift(_ x: Int) -> Int {
244+
return x << 1
245+
}
246+
247+
@_noLocks
248+
func testUintIntConversion() -> Int {
249+
let u: UInt32 = 5
250+
return Int(u)
251+
}
252+
253+
struct OptSet: OptionSet {
254+
let rawValue: Int
255+
256+
public static var a: OptSet { return OptSet(rawValue: 1) }
257+
public static var b: OptSet { return OptSet(rawValue: 2) }
258+
public static var c: OptSet { return OptSet(rawValue: 4) }
259+
public static var d: OptSet { return OptSet(rawValue: 8) }
260+
}
261+
262+
@_noLocks
263+
func testOptionSet(_ options: OptSet) -> Bool {
264+
return options.contains(.b)
265+
}
266+
267+
let globalA = 0xff
268+
let globalB = UInt32(globalA)
269+
270+
@_noLocks
271+
func testGlobalsWithConversion() -> UInt32 {
272+
return globalB
273+
}
274+

0 commit comments

Comments
 (0)