Skip to content

Add checks to unit tests for ArrayPropertyOpt #35360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/SILOptimizer/LoopTransforms/ArrayOpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace swift {
/// Projections over the aggregate that do not access the struct are ignored.
///
/// StructLoads records loads of the struct value.
/// StructAddressUsers records other uses of the struct address.
/// StructAddressUsers records all uses of the struct address.
/// StructValueUsers records direct uses of the loaded struct.
///
/// Projections of the struct over its elements are all similarly recorded in
Expand Down
5 changes: 4 additions & 1 deletion lib/SILOptimizer/LoopTransforms/ArrayPropertyOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ class ArrayPropertiesAnalysis {
/// new array onto it.
bool checkSafeArrayAddressUses(UserList &AddressUsers) {
for (auto *UseInst : AddressUsers) {

if (UseInst->isDebugInstruction())
continue;

Expand All @@ -263,6 +262,10 @@ class ArrayPropertiesAnalysis {
continue;
}

if (isa<LoadInst>(UseInst)) {
continue;
}

if (auto *AI = dyn_cast<ApplyInst>(UseInst)) {
if (ArraySemanticsCall(AI))
continue;
Expand Down
54 changes: 53 additions & 1 deletion test/SILOptimizer/array_specialize.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-sil-verify-all %s -array-property-opt
// RUN: %target-sil-opt -enable-sil-verify-all %s -array-property-opt | %FileCheck %s

sil_stage canonical

Expand All @@ -21,6 +21,18 @@ enum MyBool{
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 {
Expand Down Expand Up @@ -55,6 +67,13 @@ bb6:
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>
Expand Down Expand Up @@ -95,6 +114,17 @@ bb0(%0: $MyArray<MyClass>):

sil @throwing_fun : $@convention(thin) () -> (MyBool, @error 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 Error) {
bb0(%0 : $*MyArray<MyClass>, %1 : $*MyBool):
%3 = load %0 : $*MyArray<MyClass>
Expand Down Expand Up @@ -122,6 +152,17 @@ 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>
Expand Down Expand Up @@ -163,6 +204,17 @@ 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>
Expand Down