@@ -1667,6 +1667,11 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
1667
1667
return true ;
1668
1668
}
1669
1669
1670
+ MemoryUseOrDef *MA = MSSA->getMemoryAccess (M);
1671
+ if (!MA)
1672
+ // Degenerate case: memcpy marked as not accessing memory.
1673
+ return false ;
1674
+
1670
1675
// If copying from a constant, try to turn the memcpy into a memset.
1671
1676
if (auto *GV = dyn_cast<GlobalVariable>(M->getSource ()))
1672
1677
if (GV->isConstant () && GV->hasDefinitiveInitializer ())
@@ -1675,8 +1680,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
1675
1680
IRBuilder<> Builder (M);
1676
1681
Instruction *NewM = Builder.CreateMemSet (
1677
1682
M->getRawDest (), ByteVal, M->getLength (), M->getDestAlign (), false );
1678
- auto *LastDef =
1679
- cast<MemoryDef>(MSSAU->getMemorySSA ()->getMemoryAccess (M));
1683
+ auto *LastDef = cast<MemoryDef>(MA);
1680
1684
auto *NewAccess =
1681
1685
MSSAU->createMemoryAccessAfter (NewM, nullptr , LastDef);
1682
1686
MSSAU->insertDef (cast<MemoryDef>(NewAccess), /* RenameUses=*/ true );
@@ -1687,7 +1691,6 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
1687
1691
}
1688
1692
1689
1693
BatchAAResults BAA (*AA);
1690
- MemoryUseOrDef *MA = MSSA->getMemoryAccess (M);
1691
1694
// FIXME: Not using getClobberingMemoryAccess() here due to PR54682.
1692
1695
MemoryAccess *AnyClobber = MA->getDefiningAccess ();
1693
1696
MemoryLocation DestLoc = MemoryLocation::getForDest (M);
0 commit comments