@@ -1010,8 +1010,7 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpyLoad,
10101010 // Lifetime of srcAlloca ends at lifetime.end.
10111011 if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
10121012 if (II->getIntrinsicID () == Intrinsic::lifetime_end &&
1013- II->getArgOperand (1 )->stripPointerCasts () == srcAlloca &&
1014- cast<ConstantInt>(II->getArgOperand (0 ))->uge (srcSize))
1013+ II->getArgOperand (1 ) == srcAlloca)
10151014 break ;
10161015 }
10171016
@@ -1384,39 +1383,17 @@ bool MemCpyOptPass::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
13841383 return true ;
13851384}
13861385
1387- // / Determine whether the pointer V had only undefined content (due to Def) up
1388- // / to the given Size, either because it was freshly alloca'd or started its
1389- // / lifetime.
1386+ // / Determine whether the pointer V had only undefined content (due to Def),
1387+ // / either because it was freshly alloca'd or started its lifetime.
13901388static bool hasUndefContents (MemorySSA *MSSA, BatchAAResults &AA, Value *V,
1391- MemoryDef *Def, Value *Size ) {
1389+ MemoryDef *Def) {
13921390 if (MSSA->isLiveOnEntryDef (Def))
13931391 return isa<AllocaInst>(getUnderlyingObject (V));
13941392
1395- if (auto *II = dyn_cast_or_null<IntrinsicInst>(Def->getMemoryInst ())) {
1396- if (II->getIntrinsicID () == Intrinsic::lifetime_start) {
1397- auto *LTSize = cast<ConstantInt>(II->getArgOperand (0 ));
1398-
1399- if (auto *CSize = dyn_cast<ConstantInt>(Size)) {
1400- if (AA.isMustAlias (V, II->getArgOperand (1 )) &&
1401- LTSize->getZExtValue () >= CSize->getZExtValue ())
1402- return true ;
1403- }
1404-
1405- // If the lifetime.start covers a whole alloca (as it almost always
1406- // does) and we're querying a pointer based on that alloca, then we know
1407- // the memory is definitely undef, regardless of how exactly we alias.
1408- // The size also doesn't matter, as an out-of-bounds access would be UB.
1409- if (auto *Alloca = dyn_cast<AllocaInst>(getUnderlyingObject (V))) {
1410- if (getUnderlyingObject (II->getArgOperand (1 )) == Alloca) {
1411- const DataLayout &DL = Alloca->getDataLayout ();
1412- if (std::optional<TypeSize> AllocaSize =
1413- Alloca->getAllocationSize (DL))
1414- if (*AllocaSize == LTSize->getValue ())
1415- return true ;
1416- }
1417- }
1418- }
1419- }
1393+ if (auto *II = dyn_cast_or_null<IntrinsicInst>(Def->getMemoryInst ()))
1394+ if (II->getIntrinsicID () == Intrinsic::lifetime_start)
1395+ if (auto *Alloca = dyn_cast<AllocaInst>(getUnderlyingObject (V)))
1396+ return II->getArgOperand (1 ) == Alloca;
14201397
14211398 return false ;
14221399}
@@ -1428,13 +1405,12 @@ static bool hasUndefContents(MemorySSA *MSSA, BatchAAResults &AA, Value *V,
14281405// which cannot deal with offsets), we use the full 0..CopySize range.
14291406static bool overreadUndefContents (MemorySSA *MSSA, MemCpyInst *MemCpy,
14301407 MemIntrinsic *MemSrc, BatchAAResults &BAA) {
1431- Value *CopySize = MemCpy->getLength ();
14321408 MemoryLocation MemCpyLoc = MemoryLocation::getForSource (MemCpy);
14331409 MemoryUseOrDef *MemSrcAccess = MSSA->getMemoryAccess (MemSrc);
14341410 MemoryAccess *Clobber = MSSA->getWalker ()->getClobberingMemoryAccess (
14351411 MemSrcAccess->getDefiningAccess (), MemCpyLoc, BAA);
14361412 if (auto *MD = dyn_cast<MemoryDef>(Clobber))
1437- if (hasUndefContents (MSSA, BAA, MemCpy->getSource (), MD, CopySize ))
1413+ if (hasUndefContents (MSSA, BAA, MemCpy->getSource (), MD))
14381414 return true ;
14391415 return false ;
14401416}
@@ -1836,7 +1812,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
18361812 }
18371813 }
18381814
1839- if (hasUndefContents (MSSA, BAA, M->getSource (), MD, M-> getLength () )) {
1815+ if (hasUndefContents (MSSA, BAA, M->getSource (), MD)) {
18401816 LLVM_DEBUG (dbgs () << " Removed memcpy from undef\n " );
18411817 eraseInstruction (M);
18421818 ++NumMemCpyInstr;
0 commit comments