Handle constants in phi nodes properly.  This fixes test/Transforms/GVNPRE/2007-06-18-ConstantInPhi.ll

llvm-svn: 37655
diff --git a/llvm/lib/Transforms/Scalar/GVNPRE.cpp b/llvm/lib/Transforms/Scalar/GVNPRE.cpp
index 9b06664..15fecca 100644
--- a/llvm/lib/Transforms/Scalar/GVNPRE.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNPRE.cpp
@@ -927,7 +927,16 @@
       
       for (std::set<Value*>::iterator I = S.begin(), E = S.end();
            I != E; ++I) {
-        if (find_leader(anticIn, VN.lookup(*I)) == 0)
+        // For non-opaque values, we should already have a value numbering.
+        // However, for opaques, such as constants within PHI nodes, it is
+        // possible that they have not yet received a number.  Make sure they do
+        // so now.
+        uint32_t valNum = 0;
+        if (isa<BinaryOperator>(*I) || isa<CmpInst>(*I))
+          valNum = VN.lookup(*I);
+        else
+          valNum = VN.lookup_or_add(*I);
+        if (find_leader(anticIn, valNum) == 0)
           val_insert(anticIn, *I);
       }