From 1d4eb6ab0df28044d5ea43926390e8f20cf27874 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 5 Jun 2007 23:46:12 +0000 Subject: Fix a misunderstanding of the algorithm. Really, we should be tracking values and expression separately. We can get around this, however, by only keeping opaque values in TMP_GEN. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37443 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/GVNPRE.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/Transforms/Scalar/GVNPRE.cpp b/lib/Transforms/Scalar/GVNPRE.cpp index b93c70b..823d281 100644 --- a/lib/Transforms/Scalar/GVNPRE.cpp +++ b/lib/Transforms/Scalar/GVNPRE.cpp @@ -77,7 +77,7 @@ namespace { void dump_unique(ValueTable& VN, std::set& s); void clean(ValueTable VN, std::set& set); bool add(ValueTable& VN, std::set& MS, Value* V); - Value* find_leader(ValueTable VN, std::set& vals, uint32_t v); + Value* find_leader(ValueTable VN, std::set& vals, Value* v); Value* phi_translate(ValueTable& VN, std::set& MS, std::set& set, Value* V, BasicBlock* pred); @@ -122,10 +122,11 @@ bool GVNPRE::add(ValueTable& VN, std::set& MS, Value* V) { Value* GVNPRE::find_leader(GVNPRE::ValueTable VN, std::set& vals, - uint32_t v) { + Value* v) { + ExprLT cmp; for (std::set::iterator I = vals.begin(), E = vals.end(); I != E; ++I) - if (VN[*I] == v) + if (!cmp(v, *I) && !cmp(*I, v)) return *I; return 0; @@ -140,7 +141,7 @@ Value* GVNPRE::phi_translate(ValueTable& VN, std::set& MS, if (BinaryOperator* BO = dyn_cast(V)) { Value* newOp1 = isa(BO->getOperand(0)) ? phi_translate(VN, MS, set, - find_leader(VN, set, VN[BO->getOperand(0)]), + find_leader(VN, set, BO->getOperand(0)), pred) : BO->getOperand(0); if (newOp1 == 0) @@ -148,7 +149,7 @@ Value* GVNPRE::phi_translate(ValueTable& VN, std::set& MS, Value* newOp2 = isa(BO->getOperand(1)) ? phi_translate(VN, MS, set, - find_leader(VN, set, VN[BO->getOperand(0)]), + find_leader(VN, set, BO->getOperand(1)), pred) : BO->getOperand(1); if (newOp2 == 0) @@ -159,7 +160,7 @@ Value* GVNPRE::phi_translate(ValueTable& VN, std::set& MS, newOp1, newOp2, BO->getName()+".gvnpre"); - if (!find_leader(VN, set, VN[newVal])) { + if (!find_leader(VN, set, newVal)) { add(VN, MS, newVal); return newVal; } else { @@ -233,19 +234,21 @@ void GVNPRE::topo_sort(GVNPRE::ValueTable& VN, std::insert_iterator > q_ins(Q, Q.begin()); std::set_difference(set.begin(), set.end(), toErase.begin(), toErase.end(), - q_ins, ExprLT()); + q_ins); - std::set visited; + std::set visited; while (!Q.empty()) { Value* e = Q.back(); if (BinaryOperator* BO = dyn_cast(e)) { - Value* l = find_leader(VN, set, VN[BO->getOperand(0)]); - Value* r = find_leader(VN, set, VN[BO->getOperand(1)]); + Value* l = find_leader(VN, set, BO->getOperand(0)); + Value* r = find_leader(VN, set, BO->getOperand(1)); - if (l != 0 && visited.find(l) == visited.end()) + if (l != 0 && isa(l) && + visited.find(l) == visited.end()) Q.push_back(l); - else if (r != 0 && visited.find(r) == visited.end()) + else if (r != 0 && isa(r) && + visited.find(r) == visited.end()) Q.push_back(r); else { vec.push_back(e); @@ -316,7 +319,7 @@ void GVNPRE::CalculateAvailOut(GVNPRE::ValueTable& VN, std::set& currExps.insert(rightValue); currExps.insert(BO); - currTemps.insert(BO); + //currTemps.insert(BO); // Handle unsupported ops } else if (!BI->isTerminator()){ @@ -442,7 +445,7 @@ bool GVNPRE::runOnFunction(Function &F) { dump_unique(VN, anticIn); DOUT << "\n"; - if (old != anticIn) + if (old.size() != anticIn.size()) changed = true; anticOut.clear(); -- cgit v1.1