Changes in directory llvm/lib/Transforms/Scalar:
GVNPRE.cpp updated: 1.61 -> 1.62 --- Log message: Use cached information that has already been computed to make clean() simpler and faster. This is a small speedup on most cases. --- Diffs of the changes: (+31 -52) GVNPRE.cpp | 83 ++++++++++++++++++++++--------------------------------------- 1 files changed, 31 insertions(+), 52 deletions(-) Index: llvm/lib/Transforms/Scalar/GVNPRE.cpp diff -u llvm/lib/Transforms/Scalar/GVNPRE.cpp:1.61 llvm/lib/Transforms/Scalar/GVNPRE.cpp:1.62 --- llvm/lib/Transforms/Scalar/GVNPRE.cpp:1.61 Wed Jun 27 12:03:03 2007 +++ llvm/lib/Transforms/Scalar/GVNPRE.cpp Wed Jun 27 12:38:29 2007 @@ -429,7 +429,7 @@ // Helper fuctions // FIXME: eliminate or document these better void dump(const SmallPtrSet<Value*, 32>& s) const; - void clean(SmallPtrSet<Value*, 32>& set); + void clean(SmallPtrSet<Value*, 32>& set, BitVector& presentInSet); Value* find_leader(SmallPtrSet<Value*, 32>& vals, uint32_t v); Value* phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ); @@ -671,7 +671,7 @@ /// clean - Remove all non-opaque values from the set whose operands are not /// themselves in the set, as well as all values that depend on invokes (see /// above) -void GVNPRE::clean(SmallPtrSet<Value*, 32>& set) { +void GVNPRE::clean(SmallPtrSet<Value*, 32>& set, BitVector& presentInSet) { std::vector<Value*> worklist; worklist.reserve(set.size()); topo_sort(set, worklist); @@ -685,69 +685,43 @@ User* U = cast<User>(v); bool lhsValid = !isa<Instruction>(U->getOperand(0)); - if (!lhsValid) - for (SmallPtrSet<Value*, 32>::iterator I = set.begin(), E = set.end(); - I != E; ++I) - if (VN.lookup(*I) == VN.lookup(U->getOperand(0))) { - lhsValid = true; - break; - } + lhsValid |= presentInSet.test(VN.lookup(U->getOperand(0))); if (lhsValid) lhsValid = !dependsOnInvoke(U->getOperand(0)); bool rhsValid = !isa<Instruction>(U->getOperand(1)); - if (!rhsValid) - for (SmallPtrSet<Value*, 32>::iterator I = set.begin(), E = set.end(); - I != E; ++I) - if (VN.lookup(*I) == VN.lookup(U->getOperand(1))) { - rhsValid = true; - break; - } + rhsValid |= presentInSet.test(VN.lookup(U->getOperand(1))); if (rhsValid) rhsValid = !dependsOnInvoke(U->getOperand(1)); - if (!lhsValid || !rhsValid) + if (!lhsValid || !rhsValid) { set.erase(U); + presentInSet.flip(VN.lookup(U)); + } // Handle ternary ops } else if (isa<ShuffleVectorInst>(v) || isa<InsertElementInst>(v)) { User* U = cast<User>(v); bool lhsValid = !isa<Instruction>(U->getOperand(0)); - if (!lhsValid) - for (SmallPtrSet<Value*, 32>::iterator I = set.begin(), E = set.end(); - I != E; ++I) - if (VN.lookup(*I) == VN.lookup(U->getOperand(0))) { - lhsValid = true; - break; - } + lhsValid |= presentInSet.test(VN.lookup(U->getOperand(0))); if (lhsValid) lhsValid = !dependsOnInvoke(U->getOperand(0)); bool rhsValid = !isa<Instruction>(U->getOperand(1)); - if (!rhsValid) - for (SmallPtrSet<Value*, 32>::iterator I = set.begin(), E = set.end(); - I != E; ++I) - if (VN.lookup(*I) == VN.lookup(U->getOperand(1))) { - rhsValid = true; - break; - } + rhsValid |= presentInSet.test(VN.lookup(U->getOperand(1))); if (rhsValid) rhsValid = !dependsOnInvoke(U->getOperand(1)); bool thirdValid = !isa<Instruction>(U->getOperand(2)); - if (!thirdValid) - for (SmallPtrSet<Value*, 32>::iterator I = set.begin(), E = set.end(); - I != E; ++I) - if (VN.lookup(*I) == VN.lookup(U->getOperand(2))) { - thirdValid = true; - break; - } + thirdValid |= presentInSet.test(VN.lookup(U->getOperand(2))); if (thirdValid) thirdValid = !dependsOnInvoke(U->getOperand(2)); - if (!lhsValid || !rhsValid || !thirdValid) + if (!lhsValid || !rhsValid || !thirdValid) { set.erase(U); + presentInSet.flip(VN.lookup(U)); + } } } } @@ -1042,17 +1016,18 @@ if (defer) return 0; - - anticIn.clear(); BitVector numbers(VN.size()); for (SmallPtrSet<Value*, 32>::iterator I = anticOut.begin(), E = anticOut.end(); I != E; ++I) { - anticIn.insert(*I); unsigned num = VN.lookup_or_add(*I); numbers.resize(VN.size()); - numbers.set(num); + + if (isa<Instruction>(*I)) { + anticIn.insert(*I); + numbers.set(num); + } } for (SmallPtrSet<Value*, 32>::iterator I = currExps.begin(), E = currExps.end(); I != E; ++I) { @@ -1063,19 +1038,17 @@ } for (SmallPtrSet<Value*, 32>::iterator I = currTemps.begin(), - E = currTemps.end(); I != E; ++I) + E = currTemps.end(); I != E; ++I) { anticIn.erase(*I); + numbers.flip(VN.lookup(*I)); + } - clean(anticIn); + clean(anticIn, numbers); + anticOut.clear(); - if (old != anticIn.size()) { - DOUT << "OLD: " << old << "\n"; - DOUT << "NEW: " << anticIn.size() << "\n"; - DOUT << "ANTIC_OUT: " << anticOut.size() << "\n"; - anticOut.clear(); + if (old != anticIn.size()) return 2; - } else - anticOut.clear(); + else return 1; } @@ -1392,6 +1365,12 @@ // This phase calculates the AVAIL_OUT and ANTIC_IN sets buildsets(F); + for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) { + DOUT << "ANTIC_IN: " << FI->getName() << "\n"; + dump(anticipatedIn[FI]); + DOUT << "\n\n"; + } + // Phase 2: Insert // This phase inserts values to make partially redundant values // fully redundant _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits