Fix a bug that was causing several miscompilations on SPEC.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40746 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index e39e2eb..dfe0dff 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -658,7 +658,8 @@
                             SmallVector<Instruction*, 4>& toErase);
     bool processNonLocalLoad(LoadInst* L, SmallVector<Instruction*, 4>& toErase);
     Value *GetValueForBlock(BasicBlock *BB, LoadInst* orig,
-                                  DenseMap<BasicBlock*, Value*> &Phis);
+                            DenseMap<BasicBlock*, Value*> &Phis,
+                            bool top_level = false);
     void dump(DenseMap<BasicBlock*, Value*>& d);
   };
   
@@ -715,11 +716,12 @@
 /// GetValueForBlock - Get the value to use within the specified basic block.
 /// available values are in Phis.
 Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig,
-                               DenseMap<BasicBlock*, Value*> &Phis) { 
+                               DenseMap<BasicBlock*, Value*> &Phis,
+                               bool top_level) { 
                                  
   // If we have already computed this value, return the previously computed val.
   Value *&V = Phis[BB];
-  if (V) return V;
+  if (V && ! top_level) return V;
   
   BasicBlock* singlePred = BB->getSinglePredecessor();
   if (singlePred)
@@ -799,7 +801,7 @@
     }
   
   SmallPtrSet<BasicBlock*, 4> visited;
-  Value* v = GetValueForBlock(L->getParent(), L, repl);
+  Value* v = GetValueForBlock(L->getParent(), L, repl, true);
   
   MD.removeInstruction(L);
   L->replaceAllUsesWith(v);