@@ -78,8 +78,9 @@ static SILValue scalarizeLoad(LoadInst *LI,
78
78
SmallVector<SILValue, 4 > ElementTmps;
79
79
80
80
for (unsigned i = 0 , e = ElementAddrs.size (); i != e; ++i) {
81
- auto *SubLI = B.createLoad (LI->getLoc (), ElementAddrs[i],
82
- LoadOwnershipQualifier::Unqualified);
81
+ auto *SubLI = B.createTrivialLoadOr (LI->getLoc (), ElementAddrs[i],
82
+ LI->getOwnershipQualifier (),
83
+ true /* supports unqualified*/ );
83
84
ElementTmps.push_back (SubLI);
84
85
}
85
86
@@ -118,7 +119,7 @@ class ElementUseCollector {
118
119
119
120
private:
120
121
LLVM_NODISCARD bool collectUses (SILValue Pointer);
121
- LLVM_NODISCARD bool collectContainerUses (AllocBoxInst *ABI );
122
+ LLVM_NODISCARD bool collectContainerUses (SILValue boxValue );
122
123
};
123
124
} // end anonymous namespace
124
125
@@ -130,8 +131,10 @@ bool ElementUseCollector::collectFrom() {
130
131
return collectUses (TheMemory.getAddress ());
131
132
}
132
133
133
- bool ElementUseCollector::collectContainerUses (AllocBoxInst *abi) {
134
- for (auto *ui : abi->getUses ()) {
134
+ bool ElementUseCollector::collectContainerUses (SILValue boxValue) {
135
+ assert (isa<AllocBoxInst>(boxValue) || isa<CopyValueInst>(boxValue));
136
+
137
+ for (auto *ui : boxValue->getUses ()) {
135
138
auto *user = ui->getUser ();
136
139
137
140
// dealloc_box deallocated a box containing uninitialized memory. This can
@@ -143,6 +146,14 @@ bool ElementUseCollector::collectContainerUses(AllocBoxInst *abi) {
143
146
if (isa<StrongRetainInst>(user) || isa<RetainValueInst>(user))
144
147
continue ;
145
148
149
+ // Like retaining, copies do not effect the underlying value. We do need to
150
+ // recursively visit the copies users though.
151
+ if (auto *cvi = dyn_cast<CopyValueInst>(user)) {
152
+ if (!collectContainerUses (cvi))
153
+ return false ;
154
+ continue ;
155
+ }
156
+
146
157
// Since we are trying to promote loads/stores, any releases of the box are
147
158
// not considered uses of the underlying value due to:
148
159
//
@@ -162,7 +173,8 @@ bool ElementUseCollector::collectContainerUses(AllocBoxInst *abi) {
162
173
// FIXME: Since we do not support promoting strong_release or release_value
163
174
// today this will cause the underlying allocation to never be
164
175
// eliminated. That should be implemented and fixed.
165
- if (isa<StrongReleaseInst>(user) || isa<ReleaseValueInst>(user)) {
176
+ if (isa<StrongReleaseInst>(user) || isa<ReleaseValueInst>(user) ||
177
+ isa<DestroyValueInst>(user)) {
166
178
Releases.push_back (user);
167
179
continue ;
168
180
}
@@ -433,8 +445,9 @@ bool ElementUseCollector::collectUses(SILValue Pointer) {
433
445
getScalarizedElements (SI->getOperand (0 ), ElementTmps, SI->getLoc (), B);
434
446
435
447
for (unsigned i = 0 , e = ElementAddrs.size (); i != e; ++i)
436
- B.createStore (SI->getLoc (), ElementTmps[i], ElementAddrs[i],
437
- StoreOwnershipQualifier::Unqualified);
448
+ B.createTrivialStoreOr (SI->getLoc (), ElementTmps[i], ElementAddrs[i],
449
+ SI->getOwnershipQualifier (),
450
+ true /* supports unqualified*/ );
438
451
SI->eraseFromParent ();
439
452
continue ;
440
453
}
0 commit comments