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

Commit ba52c6e

Browse files
authored
Merge pull request #103 from dotdash/mlsm
Mark MergedLoadStoreMotion as not preserving MemDep results
2 parents 9f81bea + 43343c4 commit ba52c6e

File tree

2 files changed

+30
-41
lines changed

2 files changed

+30
-41
lines changed

lib/Transforms/Scalar/MergedLoadStoreMotion.cpp

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
#include "llvm/Analysis/CFG.h"
8181
#include "llvm/Analysis/GlobalsModRef.h"
8282
#include "llvm/Analysis/Loads.h"
83-
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
8483
#include "llvm/Analysis/ValueTracking.h"
8584
#include "llvm/IR/Metadata.h"
8685
#include "llvm/Support/Debug.h"
@@ -97,7 +96,6 @@ namespace {
9796
// MergedLoadStoreMotion Pass
9897
//===----------------------------------------------------------------------===//
9998
class MergedLoadStoreMotion {
100-
MemoryDependenceResults *MD = nullptr;
10199
AliasAnalysis *AA = nullptr;
102100

103101
// The mergeLoad/Store algorithms could have Size0 * Size1 complexity,
@@ -107,14 +105,9 @@ class MergedLoadStoreMotion {
107105
const int MagicCompileTimeControl = 250;
108106

109107
public:
110-
bool run(Function &F, MemoryDependenceResults *MD, AliasAnalysis &AA);
108+
bool run(Function &F, AliasAnalysis &AA);
111109

112110
private:
113-
///
114-
/// \brief Remove instruction from parent and update memory dependence
115-
/// analysis.
116-
///
117-
void removeInstruction(Instruction *Inst);
118111
BasicBlock *getDiamondTail(BasicBlock *BB);
119112
bool isDiamondHead(BasicBlock *BB);
120113
// Routines for sinking stores
@@ -127,22 +120,6 @@ class MergedLoadStoreMotion {
127120
};
128121
} // end anonymous namespace
129122

130-
///
131-
/// \brief Remove instruction from parent and update memory dependence analysis.
132-
///
133-
void MergedLoadStoreMotion::removeInstruction(Instruction *Inst) {
134-
// Notify the memory dependence analysis.
135-
if (MD) {
136-
MD->removeInstruction(Inst);
137-
if (auto *LI = dyn_cast<LoadInst>(Inst))
138-
MD->invalidateCachedPointerInfo(LI->getPointerOperand());
139-
if (Inst->getType()->isPtrOrPtrVectorTy()) {
140-
MD->invalidateCachedPointerInfo(Inst);
141-
}
142-
}
143-
Inst->eraseFromParent();
144-
}
145-
146123
///
147124
/// \brief Return tail block of a diamond.
148125
///
@@ -236,8 +213,6 @@ PHINode *MergedLoadStoreMotion::getPHIOperand(BasicBlock *BB, StoreInst *S0,
236213
&BB->front());
237214
NewPN->addIncoming(Opd1, S0->getParent());
238215
NewPN->addIncoming(Opd2, S1->getParent());
239-
if (MD && NewPN->getType()->isPtrOrPtrVectorTy())
240-
MD->invalidateCachedPointerInfo(NewPN);
241216
return NewPN;
242217
}
243218

@@ -275,12 +250,12 @@ bool MergedLoadStoreMotion::sinkStore(BasicBlock *BB, StoreInst *S0,
275250
// New PHI operand? Use it.
276251
if (PHINode *NewPN = getPHIOperand(BB, S0, S1))
277252
SNew->setOperand(0, NewPN);
278-
removeInstruction(S0);
279-
removeInstruction(S1);
253+
S0->eraseFromParent();
254+
S1->eraseFromParent();
280255
A0->replaceAllUsesWith(ANew);
281-
removeInstruction(A0);
256+
A0->eraseFromParent();
282257
A1->replaceAllUsesWith(ANew);
283-
removeInstruction(A1);
258+
A1->eraseFromParent();
284259
return true;
285260
}
286261
return false;
@@ -344,9 +319,7 @@ bool MergedLoadStoreMotion::mergeStores(BasicBlock *T) {
344319
return MergedStores;
345320
}
346321

347-
bool MergedLoadStoreMotion::run(Function &F, MemoryDependenceResults *MD,
348-
AliasAnalysis &AA) {
349-
this->MD = MD;
322+
bool MergedLoadStoreMotion::run(Function &F, AliasAnalysis &AA) {
350323
this->AA = &AA;
351324

352325
bool Changed = false;
@@ -382,17 +355,14 @@ class MergedLoadStoreMotionLegacyPass : public FunctionPass {
382355
if (skipFunction(F))
383356
return false;
384357
MergedLoadStoreMotion Impl;
385-
auto *MDWP = getAnalysisIfAvailable<MemoryDependenceWrapperPass>();
386-
return Impl.run(F, MDWP ? &MDWP->getMemDep() : nullptr,
387-
getAnalysis<AAResultsWrapperPass>().getAAResults());
358+
return Impl.run(F, getAnalysis<AAResultsWrapperPass>().getAAResults());
388359
}
389360

390361
private:
391362
void getAnalysisUsage(AnalysisUsage &AU) const override {
392363
AU.setPreservesCFG();
393364
AU.addRequired<AAResultsWrapperPass>();
394365
AU.addPreserved<GlobalsAAWrapperPass>();
395-
AU.addPreserved<MemoryDependenceWrapperPass>();
396366
}
397367
};
398368

@@ -408,22 +378,19 @@ FunctionPass *llvm::createMergedLoadStoreMotionPass() {
408378

409379
INITIALIZE_PASS_BEGIN(MergedLoadStoreMotionLegacyPass, "mldst-motion",
410380
"MergedLoadStoreMotion", false, false)
411-
INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
412381
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
413382
INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass, "mldst-motion",
414383
"MergedLoadStoreMotion", false, false)
415384

416385
PreservedAnalyses
417386
MergedLoadStoreMotionPass::run(Function &F, FunctionAnalysisManager &AM) {
418387
MergedLoadStoreMotion Impl;
419-
auto *MD = AM.getCachedResult<MemoryDependenceAnalysis>(F);
420388
auto &AA = AM.getResult<AAManager>(F);
421-
if (!Impl.run(F, MD, AA))
389+
if (!Impl.run(F, AA))
422390
return PreservedAnalyses::all();
423391

424392
PreservedAnalyses PA;
425393
PA.preserveSet<CFGAnalyses>();
426394
PA.preserve<GlobalsAA>();
427-
PA.preserve<MemoryDependenceAnalysis>();
428395
return PA;
429396
}

test/Transforms/GVN/pr36063.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: opt < %s -memcpyopt -mldst-motion -gvn -S | FileCheck %s
2+
3+
define void @foo(i8* %ret, i1 %x) {
4+
%a = alloca i8
5+
br i1 %x, label %yes, label %no
6+
7+
yes: ; preds = %0
8+
%gepa = getelementptr i8, i8* %a, i64 0
9+
store i8 5, i8* %gepa
10+
br label %out
11+
12+
no: ; preds = %0
13+
%gepb = getelementptr i8, i8* %a, i64 0
14+
store i8 5, i8* %gepb
15+
br label %out
16+
17+
out: ; preds = %no, %yes
18+
%tmp = load i8, i8* %a
19+
; CHECK-NOT: undef
20+
store i8 %tmp, i8* %ret
21+
ret void
22+
}

0 commit comments

Comments
 (0)