Skip to content

Commit eb3fa49

Browse files
committed
Use current insertion block as other incoming phi for each array element
1 parent eb5ce15 commit eb3fa49

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

lib/IRGen/GenArray.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,21 @@ class ArrayTypeInfoBase : public BaseTypeInfo {
9494
}
9595

9696
body(eltAddrs);
97-
97+
98+
// The just ran body may have generated new blocks. Get the current
99+
// insertion block which will become the other incoming block to the phis
100+
// we've generated.
101+
predBB = IGF.Builder.GetInsertBlock();
102+
98103
for (unsigned i : indices(addrPhis)) {
99104
addrPhis[i]->addIncoming(Element.indexArray(IGF, eltAddrs[i], one,
100105
getElementSILType(IGF.IGM, T))
101106
.getAddress(),
102-
loopBB);
107+
predBB);
103108
}
104109

105110
auto nextCount = IGF.Builder.CreateSub(countPhi, one);
106-
countPhi->addIncoming(nextCount, loopBB);
111+
countPhi->addIncoming(nextCount, predBB);
107112

108113
auto done = IGF.Builder.CreateICmpEQ(nextCount, zero);
109114
IGF.Builder.CreateCondBr(done, endBB, loopBB);

test/IRGen/array_type_layout.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: %target-swift-frontend -emit-ir -disable-availability-checking -enable-experimental-feature ValueGenerics %s | %FileCheck %s
2+
3+
// REQUIRES: swift_feature_ValueGenerics
4+
5+
struct VerySmallVector<T> {
6+
var inline: Vector<16, T?>
7+
var count = 0
8+
9+
init() {
10+
inline = .init(repeating: nil)
11+
}
12+
}
13+
14+
//===----------------------------------------------------------------------===//
15+
// VerySmallVector<T> initializeBufferWithCopyOfBuffer
16+
//===----------------------------------------------------------------------===//
17+
18+
// CHECK-LABEL: define {{.*}} ptr @"$s17array_type_layout15VerySmallVectorVwCP"(ptr{{.*}} %dest, ptr{{.*}} %src, ptr{{.*}} %"VerySmallVector<T>")
19+
// CHECK: [[FLAGS:%.*]] = load i32, ptr {{.*}}
20+
// CHECK-NEXT: [[INLINE_BIT:%.*]] = and i32 [[FLAGS]], 131072
21+
// CHECK-NEXT: [[IS_INLINE:%.*]] = icmp eq i32 [[INLINE_BIT]], 0
22+
// CHECK-NEXT: br i1 [[IS_INLINE]], label %[[DIRECT_BB:.*]], label %[[INDIRECT_BB:.*]]
23+
// CHECK-EMPTY:
24+
// CHECK-NEXT: [[INDIRECT_BB]]:
25+
// CHECK: br label %[[CONT_BB:.*]]
26+
// CHECK-EMPTY:
27+
// CHECK-NEXT: [[DIRECT_BB]]:
28+
// CHECK: br label %[[LOOP_BB:.*]]
29+
// CHECK-EMPTY:
30+
// CHECK-NEXT: [[LOOP_BB]]:
31+
// CHECK-NEXT: [[COUNT:%.*]] = phi i{{64|32}} [ 16, %[[DIRECT_BB]] ], [ [[SUB:%.*]], %[[PRED_BB:.*]] ]
32+
// CHECK-NEXT: [[DEST:%.*]] = phi ptr [ %dest, %[[DIRECT_BB]] ], [ [[DEST_OFFSET_PTR:%.*]], %[[PRED_BB]] ]
33+
// CHECK-NEXT: [[SRC:%.*]] = phi ptr [ %src, %[[DIRECT_BB]] ], [ [[SRC_OFFSET_PTR:%.*]], %[[PRED_BB]] ]
34+
// CHECK: [[TAG:%.*]] = call i32 %GetEnumTagSinglePayload(ptr{{.*}} [[SRC]], i32 1, ptr %T)
35+
// CHECK-NEXT: [[NIL_CHECK:%.*]] = icmp eq i32 [[TAG]], 0
36+
// CHECK-NEXT: br i1 [[NIL_CHECK]], label %[[NOT_NIL_BB:.*]], label %[[NIL_BB:.*]]
37+
// CHECK-EMPTY:
38+
// CHECK-NEXT: [[NOT_NIL_BB]]:
39+
// CHECK: {{.*}} = call ptr %InitializeWithCopy(ptr{{.*}} [[DEST]], ptr{{.*}} [[SRC]], ptr %T)
40+
41+
// CHECK: [[NIL_BB]]:
42+
// CHECK: call void @llvm.memcpy{{.*}}(ptr{{.*}} [[DEST]], ptr{{.*}} [[SRC]], i{{64|32}} {{%.*}}, i1 false)
43+
// CHECK-NEXT: br label %[[PRED_BB]]
44+
// CHECK-EMPTY:
45+
// CHECK-NEXT: [[PRED_BB]]:
46+
// CHECK: [[SUB]] = sub i{{64|32}} [[COUNT]], 1
47+
// CHECK-NEXT: [[DONE:%.*]] = icmp eq i{{64|32}} [[SUB]], 0
48+
// CHECK-NEXT: br i1 [[DONE]], label %[[END_LOOP_BB:.*]], label %[[LOOP_BB]]
49+
// CHECK-EMPTY:
50+
// CHECK-NEXT: [[END_LOOP_BB]]:
51+
// CHECK: [[DEST_COUNT_PTR:%.*]] = getelementptr inbounds i8, ptr %dest, i32 {{%.*}}
52+
// CHECK: [[SRC_COUNT_PTR:%.*]] = getelementptr inbounds i8, ptr %src, i32 {{%.*}}
53+
// CHECK-NEXT: call void @llvm.memcpy{{.*}}(ptr{{.*}} [[DEST_COUNT_PTR]], ptr{{.*}} [[SRC_COUNT_PTR]], i{{64|32}} 8, i1 false)
54+
// CHECK-NEXT: br label %[[CONT_BB]]
55+
// CHECK-EMPTY:
56+
// CHECK-NEXT: [[CONT_BB]]:
57+
// CHECK-NEXT: [[RETURN_DEST_PTR:%.*]] = phi ptr [ {{%.*}}, %[[INDIRECT_BB]] ], [ %dest, %[[END_LOOP_BB]] ]
58+
// CHECK-NEXT: ret ptr [[RETURN_DEST_PTR]]

0 commit comments

Comments
 (0)