Revert NewGVN N^2 behavior patch

llvm-svn: 276670
This commit is contained in:
Daniel Berlin 2016-07-25 18:19:49 +00:00
parent 336e919b01
commit 40765a62ad
1 changed files with 19 additions and 22 deletions

View File

@ -53,10 +53,10 @@ namespace {
// Provides a sorting function based on the execution order of two instructions. // Provides a sorting function based on the execution order of two instructions.
struct SortByDFSIn { struct SortByDFSIn {
private: private:
DenseMap<const Value *, unsigned> &DFSNumber; DenseMap<const BasicBlock *, unsigned> &DFSNumber;
public: public:
SortByDFSIn(DenseMap<const Value *, unsigned> &D) : DFSNumber(D) {} SortByDFSIn(DenseMap<const BasicBlock *, unsigned> &D) : DFSNumber(D) {}
// Returns true when A executes before B. // Returns true when A executes before B.
bool operator()(const Instruction *A, const Instruction *B) const { bool operator()(const Instruction *A, const Instruction *B) const {
@ -74,10 +74,9 @@ public:
if (NA < NB) if (NA < NB)
return true; return true;
if (NA == NB) { if (NA == NB) {
unsigned ADFS = DFSNumber.lookup(A); // Sort them in the order they occur in the same basic block.
unsigned BDFS = DFSNumber.lookup(B); BasicBlock::const_iterator AI(A), BI(B);
assert (ADFS && ADFS); return std::distance(AI, BI) < 0;
return ADFS < BDFS;
} }
return false; return false;
} }
@ -197,13 +196,9 @@ public:
VN.setMemDep(MD); VN.setMemDep(MD);
bool Res = false; bool Res = false;
// Perform DFS Numbering of blocks and instructions.
unsigned I = 0; unsigned I = 0;
for (const BasicBlock *BB : depth_first(&F.getEntryBlock())) { for (const BasicBlock *BB : depth_first(&F.getEntryBlock()))
DFSNumber.insert({BB, ++I}); DFSNumber.insert({BB, ++I});
for (auto &Inst: *BB)
DFSNumber.insert({&Inst, ++I});
}
// FIXME: use lazy evaluation of VN to avoid the fix-point computation. // FIXME: use lazy evaluation of VN to avoid the fix-point computation.
while (1) { while (1) {
@ -233,7 +228,7 @@ private:
AliasAnalysis *AA; AliasAnalysis *AA;
MemoryDependenceResults *MD; MemoryDependenceResults *MD;
const bool OptForMinSize; const bool OptForMinSize;
DenseMap<const Value *, unsigned> DFSNumber; DenseMap<const BasicBlock *, unsigned> DFSNumber;
BBSideEffectsSet BBSideEffects; BBSideEffectsSet BBSideEffects;
MemorySSA *MSSA; MemorySSA *MSSA;
int HoistedCtr; int HoistedCtr;
@ -295,14 +290,16 @@ private:
} }
/* Return true when I1 appears before I2 in the instructions of BB. */ /* Return true when I1 appears before I2 in the instructions of BB. */
bool firstInBB(const Instruction *I1, const Instruction *I2) { bool firstInBB(BasicBlock *BB, const Instruction *I1, const Instruction *I2) {
assert (I1->getParent() == I2->getParent()); for (Instruction &I : *BB) {
unsigned I1DFS = DFSNumber.lookup(I1); if (&I == I1)
unsigned I2DFS = DFSNumber.lookup(I2); return true;
assert (I1DFS && I2DFS); if (&I == I2)
return I1DFS < I2DFS; return false;
} }
llvm_unreachable("I1 and I2 not found in BB");
}
// Return true when there are users of Def in BB. // Return true when there are users of Def in BB.
bool hasMemoryUseOnPath(MemoryAccess *Def, const BasicBlock *BB, bool hasMemoryUseOnPath(MemoryAccess *Def, const BasicBlock *BB,
const Instruction *OldPt) { const Instruction *OldPt) {
@ -326,7 +323,7 @@ private:
return true; return true;
// It is only harmful to hoist when the use is before OldPt. // It is only harmful to hoist when the use is before OldPt.
if (firstInBB(MU->getMemoryInst(), OldPt)) if (firstInBB(UBB, MU->getMemoryInst(), OldPt))
return true; return true;
} }
@ -440,7 +437,7 @@ private:
if (NewBB == DBB && !MSSA->isLiveOnEntryDef(D)) if (NewBB == DBB && !MSSA->isLiveOnEntryDef(D))
if (auto *UD = dyn_cast<MemoryUseOrDef>(D)) if (auto *UD = dyn_cast<MemoryUseOrDef>(D))
if (firstInBB(NewPt, UD->getMemoryInst())) if (firstInBB(DBB, NewPt, UD->getMemoryInst()))
// Cannot move the load or store to NewPt above its definition in D. // Cannot move the load or store to NewPt above its definition in D.
return false; return false;
@ -517,7 +514,7 @@ private:
if (BB == HoistBB) { if (BB == HoistBB) {
NewHoistBB = HoistBB; NewHoistBB = HoistBB;
NewHoistPt = firstInBB(Insn, HoistPt) ? Insn : HoistPt; NewHoistPt = firstInBB(BB, Insn, HoistPt) ? Insn : HoistPt;
} else { } else {
NewHoistBB = DT->findNearestCommonDominator(HoistBB, BB); NewHoistBB = DT->findNearestCommonDominator(HoistBB, BB);
if (NewHoistBB == BB) if (NewHoistBB == BB)