Skip to content

Commit cd4260e

Browse files
authored
Merge pull request #2477 from swiftwasm/main
[pull] swiftwasm from main
2 parents e170cc7 + 050fd1c commit cd4260e

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

lib/SILOptimizer/LoopTransforms/ArrayOpt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace swift {
3131
/// Projections over the aggregate that do not access the struct are ignored.
3232
///
3333
/// StructLoads records loads of the struct value.
34-
/// StructAddressUsers records other uses of the struct address.
34+
/// StructAddressUsers records all uses of the struct address.
3535
/// StructValueUsers records direct uses of the loaded struct.
3636
///
3737
/// Projections of the struct over its elements are all similarly recorded in

lib/SILOptimizer/LoopTransforms/ArrayPropertyOpt.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ class ArrayPropertiesAnalysis {
254254
/// new array onto it.
255255
bool checkSafeArrayAddressUses(UserList &AddressUsers) {
256256
for (auto *UseInst : AddressUsers) {
257-
258257
if (UseInst->isDebugInstruction())
259258
continue;
260259

@@ -263,6 +262,10 @@ class ArrayPropertiesAnalysis {
263262
continue;
264263
}
265264

265+
if (isa<LoadInst>(UseInst)) {
266+
continue;
267+
}
268+
266269
if (auto *AI = dyn_cast<ApplyInst>(UseInst)) {
267270
if (ArraySemanticsCall(AI))
268271
continue;

test/SILOptimizer/array_specialize.sil

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all %s -array-property-opt
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -array-property-opt | %FileCheck %s
22

33
sil_stage canonical
44

@@ -21,6 +21,18 @@ enum MyBool{
2121
class MyClass {
2222
}
2323

24+
// CHECK-LABEL: sil @clone_switch_enum_exit :
25+
// CHECK: bb1:
26+
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
27+
// CHECK: apply [[FUNC1]]
28+
// CHECK: cond_br {{.*}}, bb11, bb2
29+
// CHECK: bb2:
30+
// CHECK: br bb3
31+
// CHECK: bb3:
32+
// CHECK: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
33+
// CHECK: apply [[FUNC2]]
34+
// CHECK_LABEL: } // end sil function 'clone_switch_enum_exit'
35+
2436
/// We need to split the loop exit edge from bb1 to bb3 before updating ssa form
2537
/// after cloning.
2638
sil @clone_switch_enum_exit : $@convention(thin) (@inout MyArray<MyClass>, @inout MyBool) -> MyBool {
@@ -55,6 +67,13 @@ bb6:
5567
protocol AProtocol : class {
5668
}
5769

70+
// CHECK-LABEL: sil @cant_handle_open_existential_use_outside_loop :
71+
// CHECK: bb1:
72+
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
73+
// CHECK: apply [[FUNC1]]
74+
// CHECK-NOT: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
75+
// CHECK-NOT: apply [[FUNC2]]
76+
// CHECK-LABEL: } // end sil function 'cant_handle_open_existential_use_outside_loop'
5877
sil @cant_handle_open_existential_use_outside_loop : $@convention(thin) (@inout MyArray<MyClass>, @inout MyBool, @owned AProtocol) -> MyBool {
5978
bb0(%0 : $*MyArray<MyClass>, %1 : $*MyBool, %10 : $AProtocol):
6079
%3 = load %0 : $*MyArray<MyClass>
@@ -95,6 +114,17 @@ bb0(%0: $MyArray<MyClass>):
95114

96115
sil @throwing_fun : $@convention(thin) () -> (MyBool, @error Error)
97116

117+
// CHECK-LABEL: sil @clone_try_apply_exit :
118+
// CHECK: bb1:
119+
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
120+
// CHECK: apply [[FUNC1]]
121+
// CHECK: cond_br {{.*}}, bb10, bb2
122+
// CHECK: bb2:
123+
// CHECK: br bb3
124+
// CHECK: bb3:
125+
// CHECK: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
126+
// CHECK: apply [[FUNC2]]
127+
// CHECK_LABEL: } // end sil function 'clone_try_apply_exit'
98128
sil @clone_try_apply_exit : $@convention(thin) (@inout MyArray<MyClass>, @inout MyBool) -> (MyBool, @error Error) {
99129
bb0(%0 : $*MyArray<MyClass>, %1 : $*MyBool):
100130
%3 = load %0 : $*MyArray<MyClass>
@@ -122,6 +152,17 @@ bb6(%9 : $Error):
122152
throw %9 : $Error
123153
}
124154

155+
// CHECK-LABEL: sil @dominator_update_outside_non_exit_block :
156+
// CHECK: bb1:
157+
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
158+
// CHECK: apply [[FUNC1]]
159+
// CHECK: cond_br {{.*}}, bb16, bb2
160+
// CHECK: bb2:
161+
// CHECK: br bb3
162+
// CHECK: bb3:
163+
// CHECK: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
164+
// CHECK: apply [[FUNC2]]
165+
// CHECK_LABEL: } // end sil function 'dominator_update_outside_non_exit_block'
125166
sil @dominator_update_outside_non_exit_block : $@convention(thin) (@inout MyArray<MyClass>, @inout Builtin.Int1) -> Builtin.Int1 {
126167
bb0(%0 : $*MyArray<MyClass>, %1 : $*Builtin.Int1):
127168
%3 = load %0 : $*MyArray<MyClass>
@@ -163,6 +204,17 @@ bb10:
163204
return %4 : $Builtin.Int1
164205
}
165206

207+
// CHECK-LABEL: sil @dominator_update_outside_non_exit_block_2 :
208+
// CHECK: bb1:
209+
// CHECK: [[FUNC1:%.*]] = function_ref @arrayPropertyIsNative
210+
// CHECK: apply [[FUNC1]]
211+
// CHECK: cond_br {{.*}}, bb17, bb2
212+
// CHECK: bb2:
213+
// CHECK: br bb3
214+
// CHECK: bb3:
215+
// CHECK: [[FUNC2:%.*]] = function_ref @arrayPropertyIsNative
216+
// CHECK: apply [[FUNC2]]
217+
// CHECK_LABEL: } // end sil function 'dominator_update_outside_non_exit_block_2'
166218
sil @dominator_update_outside_non_exit_block_2 : $@convention(thin) (@inout MyArray<MyClass>, @inout Builtin.Int1) -> Builtin.Int1 {
167219
bb0(%0 : $*MyArray<MyClass>, %1 : $*Builtin.Int1):
168220
%3 = load %0 : $*MyArray<MyClass>

unittests/runtime/Array.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern "C" void swift_arrayInitWithCopy(OpaqueValue *dest,
4343

4444
#define COPY_POD_TEST(kind) \
4545
ValueWitnessTable pod_witnesses; \
46+
memset(&pod_witnesses, 0, sizeof(pod_witnesses)); \
4647
initialize_pod_witness_table_size_uint32_t_stride_uint64_t(pod_witnesses); \
4748
uint64_t srcArray[3] = {0, 1, 2}; \
4849
uint64_t destArray[3] = {0x5A5A5A5AU, 0x5A5A5A5AU, 0x5A5A5A5AU}; \
@@ -296,6 +297,7 @@ extern "C" void swift_arrayDestroy(OpaqueValue *begin, size_t count,
296297

297298
TEST(TestArrayCopy, test_swift_arrayDestroyPOD) {
298299
ValueWitnessTable pod_witnesses;
300+
memset(&pod_witnesses, 0, sizeof(pod_witnesses));
299301
initialize_pod_witness_table_size_uint32_t_stride_uint64_t(pod_witnesses);
300302
uint64_t array[3] = {0, 1, 2};
301303
FullOpaqueMetadata testMetadata = {{&pod_witnesses},

0 commit comments

Comments
 (0)