If an alias is dead and so is its aliasee, then globaldce would
[oota-llvm.git] / lib / Transforms / Scalar / GVN.cpp
index 6087fd5ae9cd8f72e94ab661e81b008e47ef77c2..727d26555df9abbb849fddc824bc73735e007792 100644 (file)
@@ -666,7 +666,7 @@ void ValueTable::verifyRemoved(const Value *V) const {
 }
 
 //===----------------------------------------------------------------------===//
-//                         GVN Pass
+//                                GVN Pass
 //===----------------------------------------------------------------------===//
 
 namespace {
@@ -1035,7 +1035,7 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
     Value* v = GetValueForBlock(LI->getParent(), LI, BlockReplValues, true);
     LI->replaceAllUsesWith(v);
     
-    if (!isa<GlobalValue>(v))
+    if (isa<PHINode>(v))
       v->takeName(LI);
     if (isa<PointerType>(v->getType()))
       MD->invalidateCachedPointerInfo(v);
@@ -1132,7 +1132,7 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
   // Perform PHI construction.
   Value* v = GetValueForBlock(LI->getParent(), LI, BlockReplValues, true);
   LI->replaceAllUsesWith(v);
-  if (!isa<GlobalValue>(v))
+  if (isa<PHINode>(v))
     v->takeName(LI);
   if (isa<PointerType>(v->getType()))
     MD->invalidateCachedPointerInfo(v);
@@ -1251,7 +1251,7 @@ Value* GVN::AttemptRedundancyElimination(Instruction* orig, unsigned valno) {
     DenseMap<BasicBlock*, ValueNumberScope*>::iterator LA =
                                                        localAvail.find(Current);
     if (LA == localAvail.end()) return 0;
-    DenseMap<unsigned, Value*>::iterator V = LA->second->table.find(valno);
+    DenseMap<uint32_t, Value*>::iterator V = LA->second->table.find(valno);
     
     if (V != LA->second->table.end()) {
       // Found an instance, record it.
@@ -1313,6 +1313,8 @@ bool GVN::processInstruction(Instruction *I,
       p->replaceAllUsesWith(constVal);
       if (isa<PointerType>(constVal->getType()))
         MD->invalidateCachedPointerInfo(constVal);
+      VN.erase(p);
+      
       toErase.push_back(p);
     } else {
       localAvail[I->getParent()]->table.insert(std::make_pair(num, I));
@@ -1353,9 +1355,7 @@ bool GVN::processInstruction(Instruction *I,
   return false;
 }
 
-// GVN::runOnFunction - This is the main transformation entry point for a
-// function.
-//
+/// runOnFunction - This is the main transformation entry point for a function.
 bool GVN::runOnFunction(Function& F) {
   MD = &getAnalysis<MemoryDependenceAnalysis>();
   DT = &getAnalysis<DominatorTree>();
@@ -1602,7 +1602,7 @@ bool GVN::performPRE(Function& F) {
   return Changed || toSplit.size();
 }
 
-// iterateOnFunction - Executes one iteration of GVN
+/// iterateOnFunction - Executes one iteration of GVN
 bool GVN::iterateOnFunction(Function &F) {
   cleanupGlobalSets();