Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit bc344d5

Browse files
authored
Merge pull request #102 from dotdash/mlsm
Mark MergedLoadStoreMotion as not preserving MemDep results
2 parents 2717444 + 6ef94a5 commit bc344d5

File tree

1 file changed

+10
-43
lines changed

1 file changed

+10
-43
lines changed

lib/Transforms/Scalar/MergedLoadStoreMotion.cpp

+10-43
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
#include "llvm/Analysis/GlobalsModRef.h"
8080
#include "llvm/Analysis/Loads.h"
8181
#include "llvm/Analysis/MemoryBuiltins.h"
82-
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
8382
#include "llvm/Analysis/ValueTracking.h"
8483
#include "llvm/IR/Metadata.h"
8584
#include "llvm/IR/PatternMatch.h"
@@ -98,7 +97,6 @@ namespace {
9897
// MergedLoadStoreMotion Pass
9998
//===----------------------------------------------------------------------===//
10099
class MergedLoadStoreMotion {
101-
MemoryDependenceResults *MD = nullptr;
102100
AliasAnalysis *AA = nullptr;
103101

104102
// The mergeLoad/Store algorithms could have Size0 * Size1 complexity,
@@ -108,14 +106,9 @@ class MergedLoadStoreMotion {
108106
const int MagicCompileTimeControl = 250;
109107

110108
public:
111-
bool run(Function &F, MemoryDependenceResults *MD, AliasAnalysis &AA);
109+
bool run(Function &F, AliasAnalysis &AA);
112110

113111
private:
114-
///
115-
/// \brief Remove instruction from parent and update memory dependence
116-
/// analysis.
117-
///
118-
void removeInstruction(Instruction *Inst);
119112
BasicBlock *getDiamondTail(BasicBlock *BB);
120113
bool isDiamondHead(BasicBlock *BB);
121114
// Routines for hoisting loads
@@ -138,22 +131,6 @@ class MergedLoadStoreMotion {
138131
};
139132
} // end anonymous namespace
140133

141-
///
142-
/// \brief Remove instruction from parent and update memory dependence analysis.
143-
///
144-
void MergedLoadStoreMotion::removeInstruction(Instruction *Inst) {
145-
// Notify the memory dependence analysis.
146-
if (MD) {
147-
MD->removeInstruction(Inst);
148-
if (auto *LI = dyn_cast<LoadInst>(Inst))
149-
MD->invalidateCachedPointerInfo(LI->getPointerOperand());
150-
if (Inst->getType()->isPtrOrPtrVectorTy()) {
151-
MD->invalidateCachedPointerInfo(Inst);
152-
}
153-
}
154-
Inst->eraseFromParent();
155-
}
156-
157134
///
158135
/// \brief Return tail block of a diamond.
159136
///
@@ -273,10 +250,10 @@ void MergedLoadStoreMotion::hoistInstruction(BasicBlock *BB,
273250
HoistedInst->insertBefore(HoistPt);
274251

275252
HoistCand->replaceAllUsesWith(HoistedInst);
276-
removeInstruction(HoistCand);
253+
HoistCand->eraseFromParent();
277254
// Replace the else block instruction.
278255
ElseInst->replaceAllUsesWith(HoistedInst);
279-
removeInstruction(ElseInst);
256+
ElseInst->eraseFromParent();
280257
}
281258

282259
///
@@ -410,8 +387,6 @@ PHINode *MergedLoadStoreMotion::getPHIOperand(BasicBlock *BB, StoreInst *S0,
410387
&BB->front());
411388
NewPN->addIncoming(Opd1, S0->getParent());
412389
NewPN->addIncoming(Opd2, S1->getParent());
413-
if (MD && NewPN->getType()->getScalarType()->isPointerTy())
414-
MD->invalidateCachedPointerInfo(NewPN);
415390
return NewPN;
416391
}
417392

@@ -449,12 +424,12 @@ bool MergedLoadStoreMotion::sinkStore(BasicBlock *BB, StoreInst *S0,
449424
// New PHI operand? Use it.
450425
if (PHINode *NewPN = getPHIOperand(BB, S0, S1))
451426
SNew->setOperand(0, NewPN);
452-
removeInstruction(S0);
453-
removeInstruction(S1);
427+
S0->eraseFromParent();
428+
S1->eraseFromParent();
454429
A0->replaceAllUsesWith(ANew);
455-
removeInstruction(A0);
430+
A0->eraseFromParent();
456431
A1->replaceAllUsesWith(ANew);
457-
removeInstruction(A1);
432+
A1->eraseFromParent();
458433
return true;
459434
}
460435
return false;
@@ -518,9 +493,7 @@ bool MergedLoadStoreMotion::mergeStores(BasicBlock *T) {
518493
return MergedStores;
519494
}
520495

521-
bool MergedLoadStoreMotion::run(Function &F, MemoryDependenceResults *MD,
522-
AliasAnalysis &AA) {
523-
this->MD = MD;
496+
bool MergedLoadStoreMotion::run(Function &F, AliasAnalysis &AA) {
524497
this->AA = &AA;
525498

526499
bool Changed = false;
@@ -557,17 +530,14 @@ class MergedLoadStoreMotionLegacyPass : public FunctionPass {
557530
if (skipFunction(F))
558531
return false;
559532
MergedLoadStoreMotion Impl;
560-
auto *MDWP = getAnalysisIfAvailable<MemoryDependenceWrapperPass>();
561-
return Impl.run(F, MDWP ? &MDWP->getMemDep() : nullptr,
562-
getAnalysis<AAResultsWrapperPass>().getAAResults());
533+
return Impl.run(F, getAnalysis<AAResultsWrapperPass>().getAAResults());
563534
}
564535

565536
private:
566537
void getAnalysisUsage(AnalysisUsage &AU) const override {
567538
AU.setPreservesCFG();
568539
AU.addRequired<AAResultsWrapperPass>();
569540
AU.addPreserved<GlobalsAAWrapperPass>();
570-
AU.addPreserved<MemoryDependenceWrapperPass>();
571541
}
572542
};
573543

@@ -583,22 +553,19 @@ FunctionPass *llvm::createMergedLoadStoreMotionPass() {
583553

584554
INITIALIZE_PASS_BEGIN(MergedLoadStoreMotionLegacyPass, "mldst-motion",
585555
"MergedLoadStoreMotion", false, false)
586-
INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
587556
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
588557
INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass, "mldst-motion",
589558
"MergedLoadStoreMotion", false, false)
590559

591560
PreservedAnalyses
592561
MergedLoadStoreMotionPass::run(Function &F, FunctionAnalysisManager &AM) {
593562
MergedLoadStoreMotion Impl;
594-
auto *MD = AM.getCachedResult<MemoryDependenceAnalysis>(F);
595563
auto &AA = AM.getResult<AAManager>(F);
596-
if (!Impl.run(F, MD, AA))
564+
if (!Impl.run(F, AA))
597565
return PreservedAnalyses::all();
598566

599567
// FIXME: This should also 'preserve the CFG'.
600568
PreservedAnalyses PA;
601569
PA.preserve<GlobalsAA>();
602-
PA.preserve<MemoryDependenceAnalysis>();
603570
return PA;
604571
}

0 commit comments

Comments
 (0)