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