[llvm-commits] CVS: llvm/lib/Transforms/Scalar/GVNPRE.cpp

Owen Anderson resistor at mac.com
Tue Jun 5 16:46:37 PDT 2007



Changes in directory llvm/lib/Transforms/Scalar:

GVNPRE.cpp updated: 1.20 -> 1.21
---
Log message:

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.


---
Diffs of the changes:  (+17 -14)

 GVNPRE.cpp |   31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)


Index: llvm/lib/Transforms/Scalar/GVNPRE.cpp
diff -u llvm/lib/Transforms/Scalar/GVNPRE.cpp:1.20 llvm/lib/Transforms/Scalar/GVNPRE.cpp:1.21
--- llvm/lib/Transforms/Scalar/GVNPRE.cpp:1.20	Tue Jun  5 17:11:49 2007
+++ llvm/lib/Transforms/Scalar/GVNPRE.cpp	Tue Jun  5 18:46:12 2007
@@ -77,7 +77,7 @@
     void dump_unique(ValueTable& VN, std::set<Value*, ExprLT>& s);
     void clean(ValueTable VN, std::set<Value*, ExprLT>& set);
     bool add(ValueTable& VN, std::set<Value*, ExprLT>& MS, Value* V);
-    Value* find_leader(ValueTable VN, std::set<Value*, ExprLT>& vals, uint32_t v);
+    Value* find_leader(ValueTable VN, std::set<Value*, ExprLT>& vals, Value* v);
     Value* phi_translate(ValueTable& VN, std::set<Value*, ExprLT>& MS,
                          std::set<Value*, ExprLT>& set,
                          Value* V, BasicBlock* pred);
@@ -122,10 +122,11 @@
 
 Value* GVNPRE::find_leader(GVNPRE::ValueTable VN,
                            std::set<Value*, ExprLT>& vals,
-                           uint32_t v) {
+                           Value* v) {
+  ExprLT cmp;
   for (std::set<Value*, ExprLT>::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 @@
   if (BinaryOperator* BO = dyn_cast<BinaryOperator>(V)) {
     Value* newOp1 = isa<Instruction>(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* newOp2 = isa<Instruction>(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 @@
                                              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 @@
   std::insert_iterator<std::vector<Value*> > q_ins(Q, Q.begin());
   std::set_difference(set.begin(), set.end(),
                      toErase.begin(), toErase.end(),
-                     q_ins, ExprLT());
+                     q_ins);
   
-  std::set<Value*, ExprLT> visited;
+  std::set<Value*> visited;
   while (!Q.empty()) {
     Value* e = Q.back();
   
     if (BinaryOperator* BO = dyn_cast<BinaryOperator>(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<Instruction>(l) &&
+          visited.find(l) == visited.end())
         Q.push_back(l);
-      else if (r != 0 && visited.find(r) == visited.end())
+      else if (r != 0 && isa<Instruction>(r) &&
+               visited.find(r) == visited.end())
         Q.push_back(r);
       else {
         vec.push_back(e);
@@ -316,7 +319,7 @@
         currExps.insert(rightValue);
       currExps.insert(BO);
       
-      currTemps.insert(BO);
+      //currTemps.insert(BO);
       
     // Handle unsupported ops
     } else if (!BI->isTerminator()){
@@ -442,7 +445,7 @@
       dump_unique(VN, anticIn);
       DOUT << "\n";
       
-      if (old != anticIn)
+      if (old.size() != anticIn.size())
         changed = true;
       
       anticOut.clear();






More information about the llvm-commits mailing list