Index: include/llvm/Analysis/MemorySSAUpdater.h =================================================================== --- include/llvm/Analysis/MemorySSAUpdater.h +++ include/llvm/Analysis/MemorySSAUpdater.h @@ -198,6 +198,12 @@ /// deleted after this call. void removeBlocks(const SmallPtrSetImpl &DeadBlocks); + /// Reset optimized for uses of a given instruction, if those uses have + /// MemoryAccesses. This should be called when the instruction is about to be + /// replaced, since its replacement may change the clobber (e.g., simplify to + /// undef). + void resetOptimizeUses(const Instruction *I); + /// Get handle on MemorySSA. MemorySSA* getMemorySSA() const { return MSSA; } Index: lib/Analysis/MemorySSAUpdater.cpp =================================================================== --- lib/Analysis/MemorySSAUpdater.cpp +++ lib/Analysis/MemorySSAUpdater.cpp @@ -607,6 +607,19 @@ } } +void MemorySSAUpdater::resetOptimizeUses(const Instruction *I) { + for (auto &U : I->uses()) { + auto *UsrI = dyn_cast(U.getUser()); + if (!UsrI) + continue; + if (auto *MA = MSSA->getMemoryAccess(UsrI)) { + auto *MUD = cast(MA); + if (MUD->isOptimized()) + MUD->resetOptimized(); + } + } +} + MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB( Instruction *I, MemoryAccess *Definition, const BasicBlock *BB, MemorySSA::InsertionPlace Point) {