@@ -1667,6 +1667,11 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
16671667 return true ;
16681668 }
16691669
1670+ MemoryUseOrDef *MA = MSSA->getMemoryAccess (M);
1671+ if (!MA)
1672+ // Degenerate case: memcpy marked as not accessing memory.
1673+ return false ;
1674+
16701675 // If copying from a constant, try to turn the memcpy into a memset.
16711676 if (auto *GV = dyn_cast<GlobalVariable>(M->getSource ()))
16721677 if (GV->isConstant () && GV->hasDefinitiveInitializer ())
@@ -1675,8 +1680,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
16751680 IRBuilder<> Builder (M);
16761681 Instruction *NewM = Builder.CreateMemSet (
16771682 M->getRawDest (), ByteVal, M->getLength (), M->getDestAlign (), false );
1678- auto *LastDef =
1679- cast<MemoryDef>(MSSAU->getMemorySSA ()->getMemoryAccess (M));
1683+ auto *LastDef = cast<MemoryDef>(MA);
16801684 auto *NewAccess =
16811685 MSSAU->createMemoryAccessAfter (NewM, nullptr , LastDef);
16821686 MSSAU->insertDef (cast<MemoryDef>(NewAccess), /* RenameUses=*/ true );
@@ -1687,7 +1691,6 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
16871691 }
16881692
16891693 BatchAAResults BAA (*AA);
1690- MemoryUseOrDef *MA = MSSA->getMemoryAccess (M);
16911694 // FIXME: Not using getClobberingMemoryAccess() here due to PR54682.
16921695 MemoryAccess *AnyClobber = MA->getDefiningAccess ();
16931696 MemoryLocation DestLoc = MemoryLocation::getForDest (M);
0 commit comments