From d0954105f0b1fb72008e2f734ed34510309d5048 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 19 Jun 2007 07:35:36 +0000 Subject: [PATCH] Handle constants in phi nodes properly. This fixes test/Transforms/GVNPRE/2007-06-18-ConstantInPhi.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37655 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/GVNPRE.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Scalar/GVNPRE.cpp b/lib/Transforms/Scalar/GVNPRE.cpp index 9b0666494b4..15fecca0d8d 100644 --- a/lib/Transforms/Scalar/GVNPRE.cpp +++ b/lib/Transforms/Scalar/GVNPRE.cpp @@ -927,7 +927,16 @@ bool GVNPRE::runOnFunction(Function &F) { for (std::set::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(*I) || isa(*I)) + valNum = VN.lookup(*I); + else + valNum = VN.lookup_or_add(*I); + if (find_leader(anticIn, valNum) == 0) val_insert(anticIn, *I); }