@@ -1010,8 +1010,7 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpyLoad,
1010
1010
// Lifetime of srcAlloca ends at lifetime.end.
1011
1011
if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
1012
1012
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)
1015
1014
break ;
1016
1015
}
1017
1016
@@ -1384,39 +1383,17 @@ bool MemCpyOptPass::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
1384
1383
return true ;
1385
1384
}
1386
1385
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.
1390
1388
static bool hasUndefContents (MemorySSA *MSSA, BatchAAResults &AA, Value *V,
1391
- MemoryDef *Def, Value *Size ) {
1389
+ MemoryDef *Def) {
1392
1390
if (MSSA->isLiveOnEntryDef (Def))
1393
1391
return isa<AllocaInst>(getUnderlyingObject (V));
1394
1392
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;
1420
1397
1421
1398
return false ;
1422
1399
}
@@ -1428,13 +1405,12 @@ static bool hasUndefContents(MemorySSA *MSSA, BatchAAResults &AA, Value *V,
1428
1405
// which cannot deal with offsets), we use the full 0..CopySize range.
1429
1406
static bool overreadUndefContents (MemorySSA *MSSA, MemCpyInst *MemCpy,
1430
1407
MemIntrinsic *MemSrc, BatchAAResults &BAA) {
1431
- Value *CopySize = MemCpy->getLength ();
1432
1408
MemoryLocation MemCpyLoc = MemoryLocation::getForSource (MemCpy);
1433
1409
MemoryUseOrDef *MemSrcAccess = MSSA->getMemoryAccess (MemSrc);
1434
1410
MemoryAccess *Clobber = MSSA->getWalker ()->getClobberingMemoryAccess (
1435
1411
MemSrcAccess->getDefiningAccess (), MemCpyLoc, BAA);
1436
1412
if (auto *MD = dyn_cast<MemoryDef>(Clobber))
1437
- if (hasUndefContents (MSSA, BAA, MemCpy->getSource (), MD, CopySize ))
1413
+ if (hasUndefContents (MSSA, BAA, MemCpy->getSource (), MD))
1438
1414
return true ;
1439
1415
return false ;
1440
1416
}
@@ -1836,7 +1812,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
1836
1812
}
1837
1813
}
1838
1814
1839
- if (hasUndefContents (MSSA, BAA, M->getSource (), MD, M-> getLength () )) {
1815
+ if (hasUndefContents (MSSA, BAA, M->getSource (), MD)) {
1840
1816
LLVM_DEBUG (dbgs () << " Removed memcpy from undef\n " );
1841
1817
eraseInstruction (M);
1842
1818
++NumMemCpyInstr;
0 commit comments