Skip to content

Commit a267645

Browse files
committed
[MemCpyOpt] Don't unconditionally skip modref visitation for passthru
Previously passthrus never had effects. Now they do, if it it's a call with a ret-only capture. Always run the modref handling code, but wrap it in a quick read/write check to avoid wasting time for cases that definitely don't modref.
1 parent d398079 commit a267645

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,30 +1552,32 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store,
15521552
UseCaptureInfo CI =
15531553
DetermineUseCaptureKind(U, AI, IsDereferenceableOrNull);
15541554
// TODO(captures): Make this more precise.
1555-
if (CI.isPassthrough()) {
1556-
Worklist.push_back(UI);
1557-
continue;
1558-
}
1559-
1560-
if (capturesAnything(CI))
1555+
if (capturesAnything(CI.UseCC))
15611556
return false;
15621557

1563-
if (UI->isLifetimeStartOrEnd()) {
1564-
// We note the locations of these intrinsic calls so that we can
1565-
// delete them later if the optimization succeeds, this is safe
1566-
// since both llvm.lifetime.start and llvm.lifetime.end intrinsics
1567-
// practically fill all the bytes of the alloca with an undefined
1568-
// value, although conceptually marked as alive/dead.
1569-
int64_t Size = cast<ConstantInt>(UI->getOperand(0))->getSExtValue();
1570-
if (Size < 0 || Size == DestSize) {
1571-
LifetimeMarkers.push_back(UI);
1572-
continue;
1558+
if (UI->mayReadOrWriteMemory()) {
1559+
if (UI->isLifetimeStartOrEnd()) {
1560+
// We note the locations of these intrinsic calls so that we can
1561+
// delete them later if the optimization succeeds, this is safe
1562+
// since both llvm.lifetime.start and llvm.lifetime.end intrinsics
1563+
// practically fill all the bytes of the alloca with an undefined
1564+
// value, although conceptually marked as alive/dead.
1565+
int64_t Size = cast<ConstantInt>(UI->getOperand(0))->getSExtValue();
1566+
if (Size < 0 || Size == DestSize) {
1567+
LifetimeMarkers.push_back(UI);
1568+
continue;
1569+
}
15731570
}
1571+
if (UI->hasMetadata(LLVMContext::MD_noalias))
1572+
NoAliasInstrs.insert(UI);
1573+
if (!ModRefCallback(UI))
1574+
return false;
1575+
}
1576+
1577+
if (capturesAnything(CI.ResultCC)) {
1578+
Worklist.push_back(UI);
1579+
continue;
15741580
}
1575-
if (UI->hasMetadata(LLVMContext::MD_noalias))
1576-
NoAliasInstrs.insert(UI);
1577-
if (!ModRefCallback(UI))
1578-
return false;
15791581
}
15801582
}
15811583
return true;

0 commit comments

Comments
 (0)