|
| 1 | +// RUN: %target-sil-opt %s -onone-simplification -simplify-instruction=unchecked_addr_cast | %FileCheck %s |
| 2 | +// RUN: %target-sil-opt %s -simplification -simplify-instruction=unchecked_addr_cast | %FileCheck %s |
| 3 | + |
| 4 | +import Swift |
| 5 | +import Builtin |
| 6 | + |
| 7 | +// CHECK-LABEL: sil [ossa] @same_type : |
| 8 | +// CHECK-NOT: unchecked_addr_cast |
| 9 | +// CHECK: %1 = load [trivial] %0 |
| 10 | +// CHECK: } // end sil function 'same_type' |
| 11 | +sil [ossa] @same_type : $@convention(thin) (@inout Int) -> Int { |
| 12 | +bb0(%0 : $*Int): |
| 13 | + %1 = unchecked_addr_cast %0 to $*Int |
| 14 | + %2 = load [trivial] %1 |
| 15 | + return %2 |
| 16 | +} |
| 17 | + |
| 18 | +// CHECK-LABEL: sil [ossa] @not_same_type : |
| 19 | +// CHECK: %1 = unchecked_addr_cast %0 to $*Float |
| 20 | +// CHECK: %2 = load [trivial] %1 |
| 21 | +// CHECK: } // end sil function 'not_same_type' |
| 22 | +sil [ossa] @not_same_type : $@convention(thin) (@inout Int) -> Float { |
| 23 | +bb0(%0 : $*Int): |
| 24 | + %1 = unchecked_addr_cast %0 to $*Float |
| 25 | + %2 = load [trivial] %1 |
| 26 | + return %2 |
| 27 | +} |
| 28 | + |
| 29 | +// CHECK-LABEL: sil [ossa] @double_cast : |
| 30 | +// CHECK: %1 = unchecked_addr_cast %0 to $*Bool |
| 31 | +// CHECK: %2 = load [trivial] %1 |
| 32 | +// CHECK: } // end sil function 'double_cast' |
| 33 | +sil [ossa] @double_cast : $@convention(thin) (@inout Int) -> Bool { |
| 34 | +bb0(%0 : $*Int): |
| 35 | + %1 = unchecked_addr_cast %0 to $*Float |
| 36 | + %2 = unchecked_addr_cast %1 to $*Bool |
| 37 | + %3 = load [trivial] %2 |
| 38 | + return %3 |
| 39 | +} |
| 40 | + |
| 41 | +// CHECK-LABEL: sil [ossa] @vector_base : |
| 42 | +// CHECK: %1 = vector_base_addr %0 |
| 43 | +// CHECK: %2 = load [trivial] %1 |
| 44 | +// CHECK: } // end sil function 'vector_base' |
| 45 | +sil [ossa] @vector_base : $@convention(thin) (@inout Builtin.FixedArray<10, Int>) -> Int { |
| 46 | +bb0(%0 : $*Builtin.FixedArray<10, Int>): |
| 47 | + %1 = unchecked_addr_cast %0 to $*Int |
| 48 | + %2 = load [trivial] %1 |
| 49 | + return %2 |
| 50 | +} |
| 51 | + |
| 52 | +// CHECK-LABEL: sil [ossa] @vector_base_wrong_type : |
| 53 | +// CHECK: %1 = unchecked_addr_cast %0 to $*Bool |
| 54 | +// CHECK: %2 = load [trivial] %1 |
| 55 | +// CHECK: } // end sil function 'vector_base_wrong_type' |
| 56 | +sil [ossa] @vector_base_wrong_type : $@convention(thin) (@inout Builtin.FixedArray<10, Int>) -> Bool { |
| 57 | +bb0(%0 : $*Builtin.FixedArray<10, Int>): |
| 58 | + %1 = unchecked_addr_cast %0 to $*Bool |
| 59 | + %2 = load [trivial] %1 |
| 60 | + return %2 |
| 61 | +} |
| 62 | + |
| 63 | +// CHECK-LABEL: sil [ossa] @vector_base_function_type : |
| 64 | +// CHECK: %1 = vector_base_addr %0 |
| 65 | +// CHECK: %2 = load [copy] %1 |
| 66 | +// CHECK: } // end sil function 'vector_base_function_type' |
| 67 | +sil [ossa] @vector_base_function_type : $@convention(thin) (@inout Builtin.FixedArray<10, ()->()>) -> @owned @callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()> { |
| 68 | +bb0(%0 : $*Builtin.FixedArray<10, ()->()>): |
| 69 | + %1 = unchecked_addr_cast %0 to $*@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()> |
| 70 | + %2 = load [copy] %1 |
| 71 | + return %2 |
| 72 | +} |
| 73 | + |
0 commit comments