@@ -2191,13 +2191,18 @@ DSEState::eliminateDeadDefs(const MemoryLocationWrapper &KillingLocWrapper) {
2191
2191
// Worklist of MemoryAccesses that may be killed by
2192
2192
// "KillingLocWrapper.MemDef".
2193
2193
SmallSetVector<MemoryAccess *, 8 > ToCheck;
2194
+ // Track MemoryAccesses that have been deleted in the loop below, so we can
2195
+ // skip them. Don't use SkipStores for this, which may contain reused
2196
+ // MemoryAccess addresses.
2197
+ SmallPtrSet<MemoryAccess *, 8 > Deleted;
2198
+ [[maybe_unused]] unsigned OrigNumSkipStores = SkipStores.size ();
2194
2199
ToCheck.insert (KillingLocWrapper.MemDef ->getDefiningAccess ());
2195
2200
2196
2201
// Check if MemoryAccesses in the worklist are killed by
2197
2202
// "KillingLocWrapper.MemDef".
2198
2203
for (unsigned I = 0 ; I < ToCheck.size (); I++) {
2199
2204
MemoryAccess *Current = ToCheck[I];
2200
- if (SkipStores. count (Current))
2205
+ if (Deleted. contains (Current))
2201
2206
continue ;
2202
2207
std::optional<MemoryAccess *> MaybeDeadAccess = getDomMemoryDef (
2203
2208
KillingLocWrapper.MemDef , Current, KillingLocWrapper.MemLoc ,
@@ -2242,7 +2247,7 @@ DSEState::eliminateDeadDefs(const MemoryLocationWrapper &KillingLocWrapper) {
2242
2247
LLVM_DEBUG (dbgs () << " DSE: Remove Dead Store:\n DEAD: "
2243
2248
<< *DeadLocWrapper.DefInst << " \n KILLER: "
2244
2249
<< *KillingLocWrapper.DefInst << ' \n ' );
2245
- deleteDeadInstruction (DeadLocWrapper.DefInst );
2250
+ deleteDeadInstruction (DeadLocWrapper.DefInst , &Deleted );
2246
2251
++NumFastStores;
2247
2252
Changed = true ;
2248
2253
} else {
@@ -2281,7 +2286,7 @@ DSEState::eliminateDeadDefs(const MemoryLocationWrapper &KillingLocWrapper) {
2281
2286
2282
2287
// Remove killing store and remove any outstanding overlap
2283
2288
// intervals for the updated store.
2284
- deleteDeadInstruction (KillingSI);
2289
+ deleteDeadInstruction (KillingSI, &Deleted );
2285
2290
auto I = IOLs.find (DeadSI->getParent ());
2286
2291
if (I != IOLs.end ())
2287
2292
I->second .erase (DeadSI);
@@ -2293,12 +2298,16 @@ DSEState::eliminateDeadDefs(const MemoryLocationWrapper &KillingLocWrapper) {
2293
2298
LLVM_DEBUG (dbgs () << " DSE: Remove Dead Store:\n DEAD: "
2294
2299
<< *DeadLocWrapper.DefInst << " \n KILLER: "
2295
2300
<< *KillingLocWrapper.DefInst << ' \n ' );
2296
- deleteDeadInstruction (DeadLocWrapper.DefInst );
2301
+ deleteDeadInstruction (DeadLocWrapper.DefInst , &Deleted );
2297
2302
++NumFastStores;
2298
2303
Changed = true ;
2299
2304
}
2300
2305
}
2301
2306
}
2307
+
2308
+ assert (SkipStores.size () - OrigNumSkipStores == Deleted.size () &&
2309
+ " SkipStores and Deleted out of sync?" );
2310
+
2302
2311
return {Changed, DeletedKillingLoc};
2303
2312
}
2304
2313
0 commit comments