mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Constant-propagate the 0 value when loading "count" or "capacity" from the empty Array, Set or Dictionary storage. On high-level SIL this optimization is also done by the ArrayCountPropagation pass, but only for Array. And even for Array it's sometimes needed to propagate the empty-array count when high-level semantics function are already inlined. Fixes an optimization deficiency for empty OptionSet literals. https://bugs.swift.org/browse/SR-12046 rdar://problem/58861171
45 lines
1.6 KiB
Swift
45 lines
1.6 KiB
Swift
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -O -sil-verify-all -module-name=test -emit-sil | %FileCheck %s
|
|
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -Osize -sil-verify-all -module-name=test -emit-sil | %FileCheck %s
|
|
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
|
|
|
|
public struct TestOptions: OptionSet {
|
|
public let rawValue: Int
|
|
public init(rawValue: Int) { self.rawValue = rawValue }
|
|
|
|
static let first = TestOptions(rawValue: 1 << 0)
|
|
static let second = TestOptions(rawValue: 1 << 1)
|
|
static let third = TestOptions(rawValue: 1 << 2)
|
|
static let fourth = TestOptions(rawValue: 1 << 3)
|
|
}
|
|
|
|
// CHECK: sil @{{.*}}returnTestOptions{{.*}}
|
|
// CHECK-NEXT: bb0:
|
|
// CHECK-NEXT: integer_literal {{.*}}, 15
|
|
// CHECK-NEXT: struct $Int
|
|
// CHECK-NEXT: struct $TestOptions
|
|
// CHECK-NEXT: return
|
|
public func returnTestOptions() -> TestOptions {
|
|
return [.first, .second, .third, .fourth]
|
|
}
|
|
|
|
// CHECK: sil @{{.*}}returnEmptyTestOptions{{.*}}
|
|
// CHECK-NEXT: bb0:
|
|
// CHECK-NEXT: integer_literal {{.*}}, 0
|
|
// CHECK-NEXT: struct $Int
|
|
// CHECK-NEXT: struct $TestOptions
|
|
// CHECK-NEXT: return
|
|
public func returnEmptyTestOptions() -> TestOptions {
|
|
return []
|
|
}
|
|
|
|
// CHECK: alloc_global @{{.*}}globalTestOptions{{.*}}
|
|
// CHECK-NEXT: global_addr
|
|
// CHECK-NEXT: integer_literal {{.*}}, 15
|
|
// CHECK-NEXT: struct $Int
|
|
// CHECK-NEXT: struct $TestOptions
|
|
// CHECK-NEXT: store
|
|
// CHECK-NEXT: tuple
|
|
// CHECK-NEXT: return
|
|
let globalTestOptions: TestOptions = [.first, .second, .third, .fourth]
|
|
|