@@ -239,21 +239,36 @@ bool ElementUseCollector::collectUses(SILValue Pointer) {
239
239
}
240
240
241
241
// Stores *to* the allocation are writes.
242
- if (isa<StoreInst>(User) && UI->getOperandNumber () == 1 ) {
243
- if (PointeeType.is <TupleType>()) {
244
- UsesToScalarize.push_back (User);
242
+ if (auto *si = dyn_cast<StoreInst>(User)) {
243
+ if (UI->getOperandNumber () == StoreInst::Dest) {
244
+ if (PointeeType.is <TupleType>()) {
245
+ UsesToScalarize.push_back (User);
246
+ continue ;
247
+ }
248
+
249
+ auto kind = ([&]() -> PMOUseKind {
250
+ switch (si->getOwnershipQualifier ()) {
251
+ // Coming out of SILGen, we assume that raw stores are
252
+ // initializations, unless they have trivial type (which we classify
253
+ // as InitOrAssign).
254
+ case StoreOwnershipQualifier::Unqualified:
255
+ if (PointeeType.isTrivial (User->getModule ()))
256
+ return PMOUseKind::InitOrAssign;
257
+ return PMOUseKind::Initialization;
258
+
259
+ case StoreOwnershipQualifier::Init:
260
+ return PMOUseKind::Initialization;
261
+
262
+ case StoreOwnershipQualifier::Assign:
263
+ return PMOUseKind::Assign;
264
+
265
+ case StoreOwnershipQualifier::Trivial:
266
+ return PMOUseKind::InitOrAssign;
267
+ }
268
+ })();
269
+ Uses.emplace_back (si, kind);
245
270
continue ;
246
271
}
247
-
248
- // Coming out of SILGen, we assume that raw stores are initializations,
249
- // unless they have trivial type (which we classify as InitOrAssign).
250
- auto Kind = ([&]() -> PMOUseKind {
251
- if (PointeeType.isTrivial (User->getModule ()))
252
- return PMOUseKind::InitOrAssign;
253
- return PMOUseKind::Initialization;
254
- })();
255
- Uses.emplace_back (User, Kind);
256
- continue ;
257
272
}
258
273
259
274
if (auto *CAI = dyn_cast<CopyAddrInst>(User)) {
0 commit comments