Skip to content

Commit 159e5b3

Browse files
authored
MemCpyOpt: avoid unnecessary getMemorySSA (NFC) (#108405)
1 parent a81a4b2 commit 159e5b3

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ Instruction *MemCpyOptPass::tryMergingIntoMemset(Instruction *StartInst,
378378
// after MemInsertPoint.
379379
MemoryUseOrDef *MemInsertPoint = nullptr;
380380
for (++BI; !BI->isTerminator(); ++BI) {
381-
auto *CurrentAcc = cast_or_null<MemoryUseOrDef>(
382-
MSSAU->getMemorySSA()->getMemoryAccess(&*BI));
381+
auto *CurrentAcc =
382+
cast_or_null<MemoryUseOrDef>(MSSA->getMemoryAccess(&*BI));
383383
if (CurrentAcc)
384384
MemInsertPoint = CurrentAcc;
385385

@@ -605,13 +605,13 @@ bool MemCpyOptPass::moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI) {
605605
// TODO: Simplify this once P will be determined by MSSA, in which case the
606606
// discrepancy can no longer occur.
607607
MemoryUseOrDef *MemInsertPoint = nullptr;
608-
if (MemoryUseOrDef *MA = MSSAU->getMemorySSA()->getMemoryAccess(P)) {
608+
if (MemoryUseOrDef *MA = MSSA->getMemoryAccess(P)) {
609609
MemInsertPoint = cast<MemoryUseOrDef>(--MA->getIterator());
610610
} else {
611611
const Instruction *ConstP = P;
612612
for (const Instruction &I : make_range(++ConstP->getReverseIterator(),
613613
++LI->getReverseIterator())) {
614-
if (MemoryUseOrDef *MA = MSSAU->getMemorySSA()->getMemoryAccess(&I)) {
614+
if (MemoryUseOrDef *MA = MSSA->getMemoryAccess(&I)) {
615615
MemInsertPoint = MA;
616616
break;
617617
}
@@ -623,7 +623,7 @@ bool MemCpyOptPass::moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI) {
623623
LLVM_DEBUG(dbgs() << "Lifting " << *I << " before " << *P << "\n");
624624
I->moveBefore(P);
625625
assert(MemInsertPoint && "Must have found insert point");
626-
if (MemoryUseOrDef *MA = MSSAU->getMemorySSA()->getMemoryAccess(I)) {
626+
if (MemoryUseOrDef *MA = MSSA->getMemoryAccess(I)) {
627627
MSSAU->moveAfter(MA, MemInsertPoint);
628628
MemInsertPoint = MA;
629629
}
@@ -697,8 +697,7 @@ bool MemCpyOptPass::processStoreOfLoad(StoreInst *SI, LoadInst *LI,
697697
LLVM_DEBUG(dbgs() << "Promoting " << *LI << " to " << *SI << " => " << *M
698698
<< "\n");
699699

700-
auto *LastDef =
701-
cast<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(SI));
700+
auto *LastDef = cast<MemoryDef>(MSSA->getMemoryAccess(SI));
702701
auto *NewAccess = MSSAU->createMemoryAccessAfter(M, nullptr, LastDef);
703702
MSSAU->insertDef(cast<MemoryDef>(NewAccess), /*RenameUses=*/true);
704703

@@ -1258,8 +1257,8 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M,
12581257
CopySourceAlign, M->getLength(), M->isVolatile());
12591258
NewM->copyMetadata(*M, LLVMContext::MD_DIAssignID);
12601259

1261-
assert(isa<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(M)));
1262-
auto *LastDef = cast<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(M));
1260+
assert(isa<MemoryDef>(MSSA->getMemoryAccess(M)));
1261+
auto *LastDef = cast<MemoryDef>(MSSA->getMemoryAccess(M));
12631262
auto *NewAccess = MSSAU->createMemoryAccessAfter(NewM, nullptr, LastDef);
12641263
MSSAU->insertDef(cast<MemoryDef>(NewAccess), /*RenameUses=*/true);
12651264

@@ -1369,12 +1368,11 @@ bool MemCpyOptPass::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
13691368
Builder.CreateMemSet(Builder.CreatePtrAdd(Dest, SrcSize),
13701369
MemSet->getOperand(1), MemsetLen, Alignment);
13711370

1372-
assert(isa<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(MemCpy)) &&
1371+
assert(isa<MemoryDef>(MSSA->getMemoryAccess(MemCpy)) &&
13731372
"MemCpy must be a MemoryDef");
13741373
// The new memset is inserted before the memcpy, and it is known that the
13751374
// memcpy's defining access is the memset about to be removed.
1376-
auto *LastDef =
1377-
cast<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(MemCpy));
1375+
auto *LastDef = cast<MemoryDef>(MSSA->getMemoryAccess(MemCpy));
13781376
auto *NewAccess =
13791377
MSSAU->createMemoryAccessBefore(NewMemSet, nullptr, LastDef);
13801378
MSSAU->insertDef(cast<MemoryDef>(NewAccess), /*RenameUses=*/true);
@@ -1479,8 +1477,7 @@ bool MemCpyOptPass::performMemCpyToMemSetOptzn(MemCpyInst *MemCpy,
14791477
Instruction *NewM =
14801478
Builder.CreateMemSet(MemCpy->getRawDest(), MemSet->getOperand(1),
14811479
CopySize, MemCpy->getDestAlign());
1482-
auto *LastDef =
1483-
cast<MemoryDef>(MSSAU->getMemorySSA()->getMemoryAccess(MemCpy));
1480+
auto *LastDef = cast<MemoryDef>(MSSA->getMemoryAccess(MemCpy));
14841481
auto *NewAccess = MSSAU->createMemoryAccessAfter(NewM, nullptr, LastDef);
14851482
MSSAU->insertDef(cast<MemoryDef>(NewAccess), /*RenameUses=*/true);
14861483

0 commit comments

Comments
 (0)