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 @@ -12,6 +12,7 @@ //===----------------------------------------------------------------===// #include "llvm/Analysis/MemorySSAUpdater.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Analysis/MemorySSA.h" #include "llvm/IR/DataLayout.h" @@ -607,6 +608,26 @@ } } +void MemorySSAUpdater::resetOptimizeUses(const Instruction *I) { + SmallSetVector Worklist; + for (const auto *Usr : I->users()) + if (auto *UsrI = dyn_cast(Usr)) + Worklist.insert(UsrI); + + for (unsigned It = 0; It < Worklist.size(); ++It) { + if (auto *MA = MSSA->getMemoryAccess(Worklist[It])) { + auto *MUD = cast(MA); + if (MUD->isOptimized()) + MUD->resetOptimized(); + } else { + for (const auto *Usr : Worklist[It]->users()) + if (auto *UsrI = dyn_cast(Usr)) + if (!Worklist.count(UsrI)) + Worklist.insert(UsrI); + } + } +} + MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB( Instruction *I, MemoryAccess *Definition, const BasicBlock *BB, MemorySSA::InsertionPlace Point) {