diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 26dec0fa9a0..9d9dcca2474 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -719,10 +719,11 @@ namespace { // This transformation requires dominator postdominator info virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesCFG(); AU.addRequired(); AU.addRequired(); AU.addRequired(); + + AU.addPreserved(); AU.addPreserved(); AU.addPreserved(); } @@ -1019,7 +1020,11 @@ bool GVN::processLoad(LoadInst *L, DenseMap &lastLoad, } Value* GVN::lookupNumber(BasicBlock* BB, uint32_t num) { - ValueNumberScope* locals = localAvail[BB]; + DenseMap::iterator I = localAvail.find(BB); + if (I == localAvail.end()) + return 0; + + ValueNumberScope* locals = I->second; while (locals) { DenseMap::iterator I = locals->table.find(num); @@ -1167,9 +1172,9 @@ bool GVN::performPRE(Function& F) { for (BasicBlock::iterator BI = CurrentBlock->begin(), BE = CurrentBlock->end(); BI != BE; ) { - if (isa(BI) || isa(BI) || - isa(BI) || isa(BI) || - isa(BI) || isa(BI)) { + if (isa(BI) || isa(BI) || + isa(BI) || BI->mayReadFromMemory() || + BI->mayWriteToMemory()) { BI++; continue; } @@ -1282,13 +1287,6 @@ bool GVN::performPRE(Function& F) { Phi->addIncoming(predMap[*PI], *PI); VN.add(Phi, valno); - - // The newly created PHI completely replaces the old instruction, - // so we need to update the maps to reflect this. - DomTreeNode* DTN = getAnalysis()[CurrentBlock]; - for (DomTreeNode::iterator UI = DTN->begin(), UE = DTN->end(); - UI != UE; ++UI) - localAvail[(*UI)->getBlock()]->table[valno] = Phi; localAvail[CurrentBlock]->table[valno] = Phi; BI->replaceAllUsesWith(Phi);