Files
swift-mirror/test/SILOptimizer/array_property_opt.sil
Erik Eckstein 70981cf95f tests: fix misspelled check prefixes
Fix the common error of using underscores instead of dashes.
In the rebranch this is an error (lit got more picky), but it also makes sense to fix the tests in the main branch
2022-11-08 17:27:48 +01:00

261 lines
6.8 KiB
Plaintext

// RUN: %target-sil-opt -parse-serialized-sil -enable-sil-verify-all %s -array-property-opt | %FileCheck %s
sil_stage canonical
import Builtin
import Swift
struct ArrayIntBuffer {
var storage : Builtin.NativeObject
}
struct MyArray<T> {
var buffer : ArrayIntBuffer
}
enum MyBool{
case True
case False
}
class MyClass {
}
// CHECK-LABEL: sil @clone_switch_enum_exit :
// CHECK: bb1:
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
// CHECK: apply [[FUNC1]]
// CHECK: cond_br {{.*}}, bb11, bb2
// CHECK: bb2:
// CHECK: br bb3
// CHECK: bb3:
// CHECK: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
// CHECK: apply [[FUNC2]]
// CHECK-LABEL: } // end sil function 'clone_switch_enum_exit'
/// We need to split the loop exit edge from bb1 to bb3 before updating ssa form
/// after cloning.
sil @clone_switch_enum_exit : $@convention(thin) (@inout MyArray<MyClass>, @inout MyBool) -> MyBool {
bb0(%0 : $*MyArray<MyClass>, %1 : $*MyBool):
%3 = load %0 : $*MyArray<MyClass>
br bb1
bb1:
%2 = function_ref @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool
%4 = load %1 : $*MyBool
retain_value %3 : $MyArray<MyClass>
%5 = apply %2(%3) : $@convention(method) (@owned MyArray<MyClass>) -> Bool
switch_enum %4 : $MyBool, case #MyBool.False!enumelt: bb5, case #MyBool.True!enumelt: bb2
bb2:
%6 = integer_literal $Builtin.Int1, -1
cond_br %6, bb3, bb4
bb3:
br bb1
bb4:
br bb6
bb5:
br bb6
bb6:
return %4 : $MyBool
}
protocol AProtocol : class {
}
// CHECK-LABEL: sil @cant_handle_open_existential_use_outside_loop :
// CHECK: bb1:
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
// CHECK: apply [[FUNC1]]
// CHECK-NOT: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
// CHECK-NOT: apply [[FUNC2]]
// CHECK-LABEL: } // end sil function 'cant_handle_open_existential_use_outside_loop'
sil @cant_handle_open_existential_use_outside_loop : $@convention(thin) (@inout MyArray<MyClass>, @inout MyBool, @owned AProtocol) -> MyBool {
bb0(%0 : $*MyArray<MyClass>, %1 : $*MyBool, %10 : $AProtocol):
%3 = load %0 : $*MyArray<MyClass>
br bb1
bb1:
%2 = function_ref @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool
%4 = load %1 : $*MyBool
retain_value %3 : $MyArray<MyClass>
%5 = apply %2(%3) : $@convention(method) (@owned MyArray<MyClass>) -> Bool
%11 = open_existential_ref %10 : $AProtocol to $@opened("B538073C-2428-11E5-AC93-C82A1428F987", AProtocol) Self
switch_enum %4 : $MyBool, case #MyBool.False!enumelt: bb5, case #MyBool.True!enumelt: bb2
bb2:
%6 = integer_literal $Builtin.Int1, -1
cond_br %6, bb3, bb4
bb3:
br bb1
bb4:
br bb6
bb5:
br bb6
bb6:
release_value %11 : $@opened("B538073C-2428-11E5-AC93-C82A1428F987", AProtocol) Self
return %4 : $MyBool
}
sil public_external [_semantics "array.props.isNativeTypeChecked"] @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool {
bb0(%0: $MyArray<MyClass>):
unreachable
}
// Make sure we can handle try_apply when splitting edges. This test used to crash.
sil @throwing_fun : $@convention(thin) () -> (MyBool, @error any Error)
// CHECK-LABEL: sil @clone_try_apply_exit :
// CHECK: bb1:
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
// CHECK: apply [[FUNC1]]
// CHECK: cond_br {{.*}}, bb10, bb2
// CHECK: bb2:
// CHECK: br bb3
// CHECK: bb3:
// CHECK: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
// CHECK: apply [[FUNC2]]
// CHECK-LABEL: } // end sil function 'clone_try_apply_exit'
sil @clone_try_apply_exit : $@convention(thin) (@inout MyArray<MyClass>, @inout MyBool) -> (MyBool, @error any Error) {
bb0(%0 : $*MyArray<MyClass>, %1 : $*MyBool):
%3 = load %0 : $*MyArray<MyClass>
br bb1
bb1:
%2 = function_ref @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool
%4 = load %1 : $*MyBool
retain_value %3 : $MyArray<MyClass>
%5 = apply %2(%3) : $@convention(method) (@owned MyArray<MyClass>) -> Bool
%7 = function_ref @throwing_fun : $@convention(thin) () -> (MyBool, @error any Error)
try_apply %7() : $@convention(thin) () -> (MyBool, @error any Error), normal bb2, error bb6
bb2(%8 : $MyBool):
%6 = integer_literal $Builtin.Int1, -1
cond_br %6, bb3, bb5
bb3:
br bb1
bb5:
return %4 : $MyBool
bb6(%9 : $Error):
throw %9 : $Error
}
// CHECK-LABEL: sil @dominator_update_outside_non_exit_block :
// CHECK: bb1:
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
// CHECK: apply [[FUNC1]]
// CHECK: cond_br {{.*}}, bb16, bb2
// CHECK: bb2:
// CHECK: br bb3
// CHECK: bb3:
// CHECK: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
// CHECK: apply [[FUNC2]]
// CHECK-LABEL: } // end sil function 'dominator_update_outside_non_exit_block'
sil @dominator_update_outside_non_exit_block : $@convention(thin) (@inout MyArray<MyClass>, @inout Builtin.Int1) -> Builtin.Int1 {
bb0(%0 : $*MyArray<MyClass>, %1 : $*Builtin.Int1):
%3 = load %0 : $*MyArray<MyClass>
br bb1
bb1:
%2 = function_ref @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool
%4 = load %1 : $*Builtin.Int1
retain_value %3 : $MyArray<MyClass>
%5 = apply %2(%3) : $@convention(method) (@owned MyArray<MyClass>) -> Bool
cond_br %4, bb2, bb7
bb2:
cond_br undef, bb3, bb6
bb3:
%6 = integer_literal $Builtin.Int1, -1
cond_br %6, bb4, bb5
bb4:
br bb1
bb5:
br bb10
bb6: // Exit block; b1 dom b4
br bb10
bb7: // Exit block; b1 dom b4
cond_br undef, bb8, bb9
bb8:
br bb10
bb9:
br bb10
bb10:
return %4 : $Builtin.Int1
}
// CHECK-LABEL: sil @dominator_update_outside_non_exit_block_2 :
// CHECK: bb1:
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
// CHECK: apply [[FUNC1]]
// CHECK: cond_br {{.*}}, bb17, bb2
// CHECK: bb2:
// CHECK: br bb3
// CHECK: bb3:
// CHECK: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
// CHECK: apply [[FUNC2]]
// CHECK-LABEL: } // end sil function 'dominator_update_outside_non_exit_block_2'
sil @dominator_update_outside_non_exit_block_2 : $@convention(thin) (@inout MyArray<MyClass>, @inout Builtin.Int1) -> Builtin.Int1 {
bb0(%0 : $*MyArray<MyClass>, %1 : $*Builtin.Int1):
%3 = load %0 : $*MyArray<MyClass>
br bb1
bb1:
%2 = function_ref @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool
%4 = load %1 : $*Builtin.Int1
retain_value %3 : $MyArray<MyClass>
%5 = apply %2(%3) : $@convention(method) (@owned MyArray<MyClass>) -> Bool
cond_br %4, bb2, bb5
bb2:
cond_br undef, bb3, bb9
bb3:
%6 = integer_literal $Builtin.Int1, -1
cond_br %6, bb4, bb10
bb4:
br bb1
bb5: // Exit block; b1 dom b4
cond_br undef, bb6, bb7
bb6: // Exit Block; b1 dom b4
br bb8
bb7:
br bb8
bb8: // Non-exit Dominated by bb1
br bb11
bb9: // Exit dominated by bb3
br bb11
bb10: // Exit dominated by bb3
br bb11
bb11: // Non-exit dominated by bb1
return %4 : $Builtin.Int1
}