@@ -284,6 +284,7 @@ static bool mayBeVisibleThroughUnwinding(Value *V, Instruction *Start,
284284
285285void MemCpyOptPass::eraseInstruction (Instruction *I) {
286286 MSSAU->removeMemoryAccess (I);
287+ EEI->removeInstruction (I);
287288 I->eraseFromParent ();
288289}
289290
@@ -638,7 +639,7 @@ bool MemCpyOptPass::processStoreOfLoad(StoreInst *SI, LoadInst *LI,
638639 if (!LI->isSimple () || !LI->hasOneUse () || LI->getParent () != SI->getParent ())
639640 return false ;
640641
641- BatchAAResults BAA (*AA);
642+ BatchAAResults BAA (*AA, EEI );
642643 auto *T = LI->getType ();
643644 // Don't introduce calls to memcpy/memmove intrinsics out of thin air if
644645 // the corresponding libcalls are not available.
@@ -1147,14 +1148,14 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M,
11471148 IRBuilder<> Builder (M);
11481149 auto *CopySource = MDep->getSource ();
11491150 Instruction *NewCopySource = nullptr ;
1150- auto CleanupOnRet = llvm::make_scope_exit ([&NewCopySource ] {
1151+ auto CleanupOnRet = llvm::make_scope_exit ([&] {
11511152 if (NewCopySource && NewCopySource->use_empty ())
11521153 // Safety: It's safe here because we will only allocate more instructions
11531154 // after finishing all BatchAA queries, but we have to be careful if we
11541155 // want to do something like this in another place. Then we'd probably
11551156 // have to delay instruction removal until all transforms on an
11561157 // instruction finished.
1157- NewCopySource-> eraseFromParent ( );
1158+ eraseInstruction (NewCopySource );
11581159 });
11591160 MaybeAlign CopySourceAlign = MDep->getSourceAlign ();
11601161 // We just need to calculate the actual size of the copy.
@@ -1751,7 +1752,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
17511752 return true ;
17521753 }
17531754
1754- BatchAAResults BAA (*AA);
1755+ BatchAAResults BAA (*AA, EEI );
17551756 // FIXME: Not using getClobberingMemoryAccess() here due to PR54682.
17561757 MemoryAccess *AnyClobber = MA->getDefiningAccess ();
17571758 MemoryLocation DestLoc = MemoryLocation::getForDest (M);
@@ -1876,7 +1877,7 @@ bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
18761877 if (!CallAccess)
18771878 return false ;
18781879 MemCpyInst *MDep = nullptr ;
1879- BatchAAResults BAA (*AA);
1880+ BatchAAResults BAA (*AA, EEI );
18801881 MemoryAccess *Clobber = MSSA->getWalker ()->getClobberingMemoryAccess (
18811882 CallAccess->getDefiningAccess (), Loc, BAA);
18821883 if (auto *MD = dyn_cast<MemoryDef>(Clobber))
@@ -1949,7 +1950,7 @@ bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
19491950// / 4. The memcpy src is not modified during the call. (ModRef check shows no
19501951// / Mod.)
19511952bool MemCpyOptPass::processImmutArgument (CallBase &CB, unsigned ArgNo) {
1952- BatchAAResults BAA (*AA);
1953+ BatchAAResults BAA (*AA, EEI );
19531954 Value *ImmutArg = CB.getArgOperand (ArgNo);
19541955
19551956 // 1. Ensure passed argument is immutable during call.
@@ -2117,6 +2118,8 @@ bool MemCpyOptPass::runImpl(Function &F, TargetLibraryInfo *TLI_,
21172118 MSSA = MSSA_;
21182119 MemorySSAUpdater MSSAU_ (MSSA_);
21192120 MSSAU = &MSSAU_;
2121+ EarliestEscapeInfo EEI_ (*DT);
2122+ EEI = &EEI_;
21202123
21212124 while (true ) {
21222125 if (!iterateOnFunction (F))
0 commit comments