Files
swift-mirror/test/SILOptimizer/constant_propagation_casts_ossa.sil
Doug Gregor 5e29333d6b [SE-0470] Enable isolated conformances by default
The IsolatedConformances feature moves to a normal, supported feature.
Remove all of the experimental-feature flags on test cases and such.

The InferIsolatedConformances feature moves to an upcoming feature for
Swift 7. This should become an adoptable feature, adding "nonisolated"
where needed.

(cherry picked from commit 3380331e7e)
2025-04-14 16:38:22 -07:00

135 lines
3.5 KiB
Plaintext

// RUN: %target-sil-opt -enable-sil-verify-all %s -diagnostic-constant-propagation | %FileCheck %s
// REQUIRES: concurrency
sil_stage canonical
import Builtin
import Swift
import _Concurrency
import SwiftShims
class Klass {
}
class SubKlass : Klass {
}
class NoSubKlass {
}
protocol P {
func f() -> Int
}
struct X : @MainActor P {
func f() -> Int
init()
}
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 : $()
}
// CHECK-LABEL: sil [ossa] @isolated_conf_ucca :
// CHECK: unconditional_checked_cast_addr
// CHECK-LABEL: } // end sil function 'isolated_conf_ucca'
sil [ossa] @isolated_conf_ucca : $@convention(thin) (@in X) -> @out P {
bb0(%0 : $*P, %1 : $*X):
unconditional_checked_cast_addr X in %1 to any P in %0
%2 = tuple ()
return %2
}
// CHECK-LABEL: sil [ossa] @isolated_conf_ccab :
// CHECK: checked_cast_addr_br
// CHECK-LABEL: } // end sil function 'isolated_conf_ccab'
sil [ossa] @isolated_conf_ccab : $@convention(thin) (@in X) -> @out P {
bb0(%0 : $*P, %1 : $*X):
checked_cast_addr_br take_always X in %1 to any P in %0, bb1, bb2
bb1:
%2 = tuple ()
return %2
bb2:
unreachable
}