Skip to content

Commit 854b7c4

Browse files
committed
WIP
1 parent 4763dd6 commit 854b7c4

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -1525,11 +1525,21 @@ bool MemCpyOptPass::processMemMove(MemMoveInst *M) {
15251525
/// This is called on every byval argument in call sites.
15261526
bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
15271527
const DataLayout &DL = CB.getCaller()->getParent()->getDataLayout();
1528-
// Find out what feeds this byval argument.
1528+
15291529
Value *ByValArg = CB.getArgOperand(ArgNo);
1530-
Type *ByValTy = CB.getParamByValType(ArgNo);
1530+
Type *ByValTy;
1531+
if (CB.isByValArgument(ArgNo)) {
1532+
ByValTy = CB.getParamByValType(ArgNo);
1533+
} else {
1534+
if (AllocaInst *Alloca = dyn_cast<AllocaInst>(ByValArg->stripPointerCasts()))
1535+
ByValTy = Alloca->getAllocatedType();
1536+
else
1537+
return false;
1538+
}
15311539
TypeSize ByValSize = DL.getTypeAllocSize(ByValTy);
1532-
MemoryLocation Loc(ByValArg, LocationSize::precise(ByValSize));
1540+
MemoryLocation Loc = MemoryLocation(ByValArg, LocationSize::precise(ByValSize));
1541+
1542+
// Find out what feeds this byval argument.
15331543
MemoryUseOrDef *CallAccess = MSSA->getMemoryAccess(&CB);
15341544
if (!CallAccess)
15351545
return false;
@@ -1627,9 +1637,14 @@ bool MemCpyOptPass::iterateOnFunction(Function &F) {
16271637
else if (auto *M = dyn_cast<MemMoveInst>(I))
16281638
RepeatInstruction = processMemMove(M);
16291639
else if (auto *CB = dyn_cast<CallBase>(I)) {
1630-
for (unsigned i = 0, e = CB->arg_size(); i != e; ++i)
1631-
if (CB->isByValArgument(i))
1640+
for (unsigned i = 0, e = CB->arg_size(); i != e; ++i) {
1641+
if (CB->isByValArgument(i) ||
1642+
(CB->paramHasAttr(i, Attribute::ReadOnly) &&
1643+
CB->paramHasAttr(i, Attribute::NoCapture) &&
1644+
CB->paramHasAttr(i, Attribute::NoAlias))) {
16321645
MadeChange |= processByValArgument(*CB, i);
1646+
}
1647+
}
16331648
}
16341649

16351650
// Reprocess the instruction if desired.

0 commit comments

Comments
 (0)