Skip to content

Commit ec5c432

Browse files
committed
LargeTypesReg2Mem: Don't ignore BuiltinFixedArrayType
rdar://139457907
1 parent e54bcef commit ec5c432

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static bool isLargeLoadableType(GenericEnvironment *GenericEnv, SILType t,
123123
canType = GenericEnv->mapTypeIntoContext(canType)->getCanonicalType();
124124
}
125125

126-
if (canType.getAnyGeneric()) {
126+
if (canType.getAnyGeneric() || t.is<BuiltinFixedArrayType>()) {
127127
assert(t.isObject() && "Expected only two categories: address and object");
128128
assert(!canType->hasTypeParameter());
129129
const TypeInfo &TI = Mod.getTypeInfoForLowered(canType);
@@ -3514,7 +3514,7 @@ class LargeLoadableHeuristic {
35143514
canType = genEnv->mapTypeIntoContext(canType)->getCanonicalType();
35153515
}
35163516

3517-
if (canType.getAnyGeneric() || isa<TupleType>(canType)) {
3517+
if (canType.getAnyGeneric() || isa<TupleType>(canType) || ty.is<BuiltinFixedArrayType>()) {
35183518
assert(ty.isObject() &&
35193519
"Expected only two categories: address and object");
35203520
assert(!canType->hasTypeParameter());

lib/SIL/IR/TypeLowering.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5264,6 +5264,16 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, TypeConverter &TC,
52645264
}
52655265
return;
52665266
}
5267+
5268+
if (auto fixedArrayTy = Ty.getAs<BuiltinFixedArrayType>()) {
5269+
auto fixedSize = fixedArrayTy->getFixedInhabitedSize();
5270+
if (fixedSize.has_value() && !fixedArrayTy->isFixedNegativeSize() )
5271+
fieldsCount += *fixedSize;
5272+
else
5273+
fieldsCount += 1;
5274+
return;
5275+
}
5276+
52675277
if (auto *enumDecl = Ty.getEnumOrBoundGenericEnum()) {
52685278
if (enumDecl->isIndirect()) {
52695279
return;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// %target-swift-frontend %s -Xllvm -sil-print-after=loadable-address -import-objc-header %S/Inputs/large_c.h -c -o %t/t.o 2>&1 | %FileCheck %s
2+
3+
// RUN: %target-swift-frontend %s -disable-availability-checking -enable-experimental-feature ValueGenerics -enable-experimental-feature BuiltinModule -Xllvm -sil-print-after=loadable-address -c -o %t/t.o 2>&1 | %FileCheck %s
4+
5+
// REQUIRES: swift_feature_BuiltinModule
6+
// REQUIRES: swift_feature_ValueGenerics
7+
8+
import Builtin
9+
import Swift
10+
11+
12+
sil_stage canonical
13+
14+
// CHECK: sil @test1 : $@convention(thin) (@in_guaranteed Builtin.FixedArray<16, Builtin.Int64>) -> () {
15+
// CHECK-NOT: load
16+
// CHECK-NOT: store
17+
// CHECK: alloc_stack $Builtin.FixedArray<16, Builtin.Int64>
18+
// CHECK-NOT: load
19+
// CHECK-NOT: store
20+
// CHECK: copy_addr [take] {{.*}} to [init] {{.*}} : $*Builtin.FixedArray<16, Builtin.Int64>
21+
// CHECK-NOT: load
22+
// CHECK-NOT: store
23+
// CHECK: } // end sil function 'test1'
24+
25+
sil @test1 : $@convention(thin) (Builtin.FixedArray<16, Builtin.Int64>) -> () {
26+
bb0(%0 : $Builtin.FixedArray<16, Builtin.Int64>):
27+
%1 = alloc_stack $Builtin.FixedArray<16, Builtin.Int64>
28+
%2 = alloc_stack $Builtin.FixedArray<16, Builtin.Int64>
29+
store %0 to %1 : $*Builtin.FixedArray<16, Builtin.Int64>
30+
%3 = load %1 : $*Builtin.FixedArray<16, Builtin.Int64>
31+
store %3 to %2 : $*Builtin.FixedArray<16, Builtin.Int64>
32+
dealloc_stack %2 : $*Builtin.FixedArray<16, Builtin.Int64>
33+
dealloc_stack %1 : $*Builtin.FixedArray<16, Builtin.Int64>
34+
%t = tuple ()
35+
return %t : $()
36+
}

0 commit comments

Comments
 (0)