Files
swift-mirror/test/SILOptimizer/generic_loop.swift
Erik Eckstein 0a71d0fbea SimplifyCFG: allow jump-threading for switch_enum_data_addr instructions.
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)
    }
  }
2020-09-30 16:44:58 +02:00

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)
}
}