mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
If the branch-block injects a certain enum case and the destination switches on that enum, it's worth jump threading. E.g.
inject_enum_addr %enum : $*Optional<T>, #Optional.some
... // no memory writes here
br DestBB
DestBB:
... // no memory writes here
switch_enum_addr %enum : $*Optional<T>, case #Optional.some ...
This enables removing all code with optionals in a loop, which iterates over an array of address-only elements, e.g.
func test<T>(_ items: [T]) {
for i in items {
print(i)
}
}
18 lines
593 B
Swift
18 lines
593 B
Swift
// RUN: %target-swift-frontend -primary-file %s -O -sil-verify-all -module-name=test -emit-sil | %FileCheck %s
|
|
|
|
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
|
|
|
|
|
|
// Check that we can eliminate all optionals from a loop which is iterating
|
|
// over an array of address-only elements.
|
|
|
|
// CHECK-LABEL: sil @$s4test0A18_no_optionals_usedyySayxGlF : $@convention(thin) <T> (@guaranteed Array<T>) -> () {
|
|
// CHECK-NOT: Optional
|
|
// CHECK: } // end sil function '$s4test0A18_no_optionals_usedyySayxGlF'
|
|
public func test_no_optionals_used<T>(_ items: [T]) {
|
|
for i in items {
|
|
print(i)
|
|
}
|
|
}
|
|
|