|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -diagnostic-constant-propagation | %FileCheck %s |
| 2 | +sil_stage canonical |
| 3 | + |
| 4 | +//import Swift |
| 5 | + |
| 6 | +class Klass { |
| 7 | +} |
| 8 | + |
| 9 | +class SubKlass : Klass { |
| 10 | +} |
| 11 | + |
| 12 | +class NoSubKlass { |
| 13 | +} |
| 14 | + |
| 15 | +sil [noinline] @blackhole1 : $@convention(thin) (@guaranteed SubKlass) -> () |
| 16 | +sil [noinline] @blackhole2 : $@convention(thin) (@guaranteed NoSubKlass) -> () |
| 17 | + |
| 18 | +// CHECK-LABEL: sil [ossa] @test_guaranteed_cast_opt1 : |
| 19 | +// CHECK-NOT: checked_cast_br |
| 20 | +// CHECK: upcast |
| 21 | +// CHECK-LABEL: } // end sil function 'test_guaranteed_cast_opt1' |
| 22 | +sil [ossa] @test_guaranteed_cast_opt1 : $@convention(thin) (@owned SubKlass) -> () { |
| 23 | +bb0(%0 : @owned $SubKlass): |
| 24 | + %borrow = begin_borrow %0 : $SubKlass |
| 25 | + checked_cast_br %borrow : $SubKlass to Klass, bb1, bb2 |
| 26 | + |
| 27 | +bb1(%val1 : @guaranteed $Klass): |
| 28 | + %copy = copy_value %val1: $Klass |
| 29 | + end_borrow %borrow : $SubKlass |
| 30 | + destroy_value %copy : $Klass |
| 31 | + br bb3 |
| 32 | + |
| 33 | +bb2(%val2 : @guaranteed $SubKlass): |
| 34 | + end_borrow %borrow : $SubKlass |
| 35 | + br bb3 |
| 36 | + |
| 37 | +bb3: |
| 38 | + destroy_value %0 : $SubKlass |
| 39 | + %r = tuple () |
| 40 | + return %r : $() |
| 41 | +} |
| 42 | + |
| 43 | +// CHECK-LABEL: sil [ossa] @test_guaranteed_cast_opt2 : |
| 44 | +// CHECK-NOT: checked_cast_br |
| 45 | +// CHECK: upcast |
| 46 | +// CHECK-LABEL: } // end sil function 'test_guaranteed_cast_opt2' |
| 47 | +sil [ossa] @test_guaranteed_cast_opt2 : $@convention(thin) (@owned SubKlass) -> () { |
| 48 | +bb0(%0 : @owned $SubKlass): |
| 49 | + %borrow = begin_borrow %0 : $SubKlass |
| 50 | + checked_cast_br %borrow : $SubKlass to Klass, bb1, bb2 |
| 51 | + |
| 52 | +bb1(%val1 : @guaranteed $Klass): |
| 53 | + %copy = copy_value %val1: $Klass |
| 54 | + end_borrow %borrow : $SubKlass |
| 55 | + destroy_value %copy : $Klass |
| 56 | + br bb3 |
| 57 | + |
| 58 | +bb2(%val2 : @guaranteed $SubKlass): |
| 59 | + %func = function_ref @blackhole1 : $@convention(thin) (@guaranteed SubKlass) -> () |
| 60 | + apply %func(%val2) : $@convention(thin) (@guaranteed SubKlass) -> () |
| 61 | + end_borrow %borrow : $SubKlass |
| 62 | + br bb3 |
| 63 | + |
| 64 | +bb3: |
| 65 | + destroy_value %0 : $SubKlass |
| 66 | + %r = tuple () |
| 67 | + return %r : $() |
| 68 | +} |
| 69 | + |
| 70 | +// CHECK-LABEL: sil [ossa] @test_guaranteed_cast_opt3 : |
| 71 | +// CHECK-NOT: checked_cast_br |
| 72 | +// CHECK: br bb2 |
| 73 | +// CHECK-LABEL: } // end sil function 'test_guaranteed_cast_opt3' |
| 74 | +sil [ossa] @test_guaranteed_cast_opt3 : $@convention(thin) (@owned NoSubKlass) -> () { |
| 75 | +bb0(%0 : @owned $NoSubKlass): |
| 76 | + %borrow = begin_borrow %0 : $NoSubKlass |
| 77 | + checked_cast_br %borrow : $NoSubKlass to Klass, bb1, bb2 |
| 78 | + |
| 79 | +bb1(%val1 : @guaranteed $Klass): |
| 80 | + %copy = copy_value %val1: $Klass |
| 81 | + end_borrow %borrow : $NoSubKlass |
| 82 | + destroy_value %copy : $Klass |
| 83 | + br bb3 |
| 84 | + |
| 85 | +bb2(%val2 : @guaranteed $NoSubKlass): |
| 86 | + %func = function_ref @blackhole2 : $@convention(thin) (@guaranteed NoSubKlass) -> () |
| 87 | + apply %func(%val2) : $@convention(thin) (@guaranteed NoSubKlass) -> () |
| 88 | + end_borrow %borrow : $NoSubKlass |
| 89 | + br bb3 |
| 90 | + |
| 91 | +bb3: |
| 92 | + destroy_value %0 : $NoSubKlass |
| 93 | + %r = tuple () |
| 94 | + return %r : $() |
| 95 | +} |
| 96 | + |
0 commit comments