Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp =================================================================== --- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -799,11 +799,12 @@ LLVM_DEBUG(dbgs() << "Promoting " << *SI << " to " << *M << "\n"); - assert(isa(MSSAU->getMemorySSA()->getMemoryAccess(SI))); - auto *LastDef = - cast(MSSAU->getMemorySSA()->getMemoryAccess(SI)); - auto *NewAccess = MSSAU->createMemoryAccessAfter(M, LastDef, LastDef); - MSSAU->insertDef(cast(NewAccess), /*RenameUses=*/true); + // The newly inserted memset is immediately overwritten by the original + // store, so we do not need to rename uses. + auto *StoreDef = cast(MSSA->getMemoryAccess(SI)); + auto *NewAccess = MSSAU->createMemoryAccessBefore( + M, StoreDef->getDefiningAccess(), StoreDef); + MSSAU->insertDef(cast(NewAccess), /*RenameUses=*/false); eraseInstruction(SI); NumMemSetInfer++;