|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=init_enum_data_addr | %FileCheck %s |
| 2 | + |
| 3 | +// REQUIRES: swift_in_compiler |
| 4 | + |
| 5 | +import Swift |
| 6 | +import Builtin |
| 7 | + |
| 8 | +enum E { |
| 9 | + case A(Int) |
| 10 | + case B(AnyObject) |
| 11 | +} |
| 12 | + |
| 13 | +enum GenE<T> { |
| 14 | + case A(Int) |
| 15 | + case B(T) |
| 16 | +} |
| 17 | +// CHECK-LABEL: sil @optional_int |
| 18 | +// CHECK: %2 = enum $Optional<Int>, #Optional.some!enumelt, %1 : $Int |
| 19 | +// CHECK: store %2 to %0 : $*Optional<Int> |
| 20 | +// CHECK: %4 = tuple () |
| 21 | +// CHECK: return %4 |
| 22 | +// CHECK: } // end sil function 'optional_int' |
| 23 | +sil @optional_int : $@convention(thin) (Int) -> @out Optional<Int> { |
| 24 | +bb0(%0 : $*Optional<Int>, %1 : $Int): |
| 25 | + %2 = init_enum_data_addr %0 : $*Optional<Int>, #Optional.some!enumelt |
| 26 | + store %1 to %2 : $*Int |
| 27 | + inject_enum_addr %0 : $*Optional<Int>, #Optional.some!enumelt |
| 28 | + %5 = tuple () |
| 29 | + return %5 : $() |
| 30 | +} |
| 31 | + |
| 32 | +// CHECK-LABEL: sil [ossa] @ossa_trivial |
| 33 | +// CHECK: %2 = enum $Optional<Int>, #Optional.some!enumelt, %1 : $Int |
| 34 | +// CHECK: store %2 to [trivial] %0 : $*Optional<Int> |
| 35 | +// CHECK: %4 = tuple () |
| 36 | +// CHECK: return %4 |
| 37 | +// CHECK: } // end sil function 'ossa_trivial' |
| 38 | +sil [ossa] @ossa_trivial : $@convention(thin) (Int) -> @out Optional<Int> { |
| 39 | +bb0(%0 : $*Optional<Int>, %1 : $Int): |
| 40 | + %2 = init_enum_data_addr %0 : $*Optional<Int>, #Optional.some!enumelt |
| 41 | + store %1 to [trivial] %2 : $*Int |
| 42 | + inject_enum_addr %0 : $*Optional<Int>, #Optional.some!enumelt |
| 43 | + %5 = tuple () |
| 44 | + return %5 : $() |
| 45 | +} |
| 46 | + |
| 47 | +// CHECK-LABEL: sil [ossa] @ossa_nontrivial |
| 48 | +// CHECK: %2 = enum $E, #E.A!enumelt, %1 : $Int |
| 49 | +// CHECK: store %2 to [init] %0 : $*E |
| 50 | +// CHECK: %4 = tuple () |
| 51 | +// CHECK: return %4 |
| 52 | +// CHECK: } // end sil function 'ossa_nontrivial' |
| 53 | +sil [ossa] @ossa_nontrivial : $@convention(thin) (Int) -> @out E { |
| 54 | +bb0(%0 : $*E, %1 : $Int): |
| 55 | + %2 = init_enum_data_addr %0 : $*E, #E.A!enumelt |
| 56 | + store %1 to [trivial] %2 : $*Int |
| 57 | + inject_enum_addr %0 : $*E, #E.A!enumelt |
| 58 | + %5 = tuple () |
| 59 | + return %5 : $() |
| 60 | +} |
| 61 | + |
| 62 | +// CHECK-LABEL: sil [ossa] @not_loadable |
| 63 | +// CHECK: %2 = init_enum_data_addr |
| 64 | +// CHECK: store %1 to [trivial] %2 |
| 65 | +// CHECK: inject_enum_addr |
| 66 | +// CHECK: } // end sil function 'not_loadable' |
| 67 | +sil [ossa] @not_loadable : $@convention(thin) <T> (Int) -> @out GenE<T> { |
| 68 | +bb0(%0 : $*GenE<T>, %1 : $Int): |
| 69 | + %2 = init_enum_data_addr %0 : $*GenE<T>, #GenE.A!enumelt |
| 70 | + store %1 to [trivial] %2 : $*Int |
| 71 | + inject_enum_addr %0 : $*GenE<T>, #GenE.A!enumelt |
| 72 | + %5 = tuple () |
| 73 | + return %5 : $() |
| 74 | +} |
| 75 | + |
0 commit comments