[llvm-commits] CVS: llvm/lib/Analysis/LoadValueNumbering.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Jan 28 22:11:31 PST 2005



Changes in directory llvm/lib/Analysis:

LoadValueNumbering.cpp updated: 1.24 -> 1.25
---
Log message:

Eliminate generality that is not buying us anything.  In particular, this
will cause us to miss cases where the input pointer to a load could be value
numbered to another load.  Something like this:


  %X = load int* %P1
  %Y = load int* %P2

Those are obviously the same if P1/P2 are the same.  The code this patch 
removes attempts to handle that.  However, since GCSE iterates, this doesn't 
actually buy us anything: GCSE will first replace P1 or P2 with the other
one, then the load can be value numbered as equal.

Removing this code speeds up gcse a lot.  On 176.gcc in debug mode, this
speeds up gcse from 29.08s -> 25.73s, a 13% savings.


---
Diffs of the changes:  (+13 -32)

 LoadValueNumbering.cpp |   45 +++++++++++++--------------------------------
 1 files changed, 13 insertions(+), 32 deletions(-)


Index: llvm/lib/Analysis/LoadValueNumbering.cpp
diff -u llvm/lib/Analysis/LoadValueNumbering.cpp:1.24 llvm/lib/Analysis/LoadValueNumbering.cpp:1.25
--- llvm/lib/Analysis/LoadValueNumbering.cpp:1.24	Fri Jan 28 23:57:01 2005
+++ llvm/lib/Analysis/LoadValueNumbering.cpp	Sat Jan 29 00:11:16 2005
@@ -284,17 +284,7 @@
   if (LI->isVolatile())
     return getAnalysis<ValueNumbering>().getEqualNumberNodes(V, RetVals);
   
-  // If we have a load instruction, find all of the load and store instructions
-  // that use the same source operand.  We implement this recursively, because
-  // there could be a load of a load of a load that are all identical.  We are
-  // guaranteed that this cannot be an infinite recursion because load
-  // instructions would have to pass through a PHI node in order for there to be
-  // a cycle.  The PHI node would be handled by the else case here, breaking the
-  // infinite recursion.
-  //
-  std::vector<Value*> PointerSources;
-  getEqualNumberNodes(LI->getOperand(0), PointerSources);
-  PointerSources.push_back(LI->getOperand(0));
+  Value *PointerSource = LI->getOperand(0);
   
   BasicBlock *LoadBB = LI->getParent();
   Function *F = LoadBB->getParent();
@@ -305,27 +295,18 @@
   //
   std::map<BasicBlock*, std::vector<LoadInst*> >  CandidateLoads;
   std::map<BasicBlock*, std::vector<StoreInst*> > CandidateStores;
-  std::set<AllocationInst*> Allocations;
-  
-  while (!PointerSources.empty()) {
-    Value *Source = PointerSources.back();
-    PointerSources.pop_back();                // Get a source pointer...
-
-    if (AllocationInst *AI = dyn_cast<AllocationInst>(Source))
-      Allocations.insert(AI);
     
-    for (Value::use_iterator UI = Source->use_begin(), UE = Source->use_end();
-         UI != UE; ++UI)
-      if (LoadInst *Cand = dyn_cast<LoadInst>(*UI)) {// Is a load of source?
-        if (Cand->getParent()->getParent() == F &&   // In the same function?
-            Cand != LI && !Cand->isVolatile())       // Not LI itself?
-          CandidateLoads[Cand->getParent()].push_back(Cand);     // Got one...
-      } else if (StoreInst *Cand = dyn_cast<StoreInst>(*UI)) {
-        if (Cand->getParent()->getParent() == F && !Cand->isVolatile() &&
-            Cand->getOperand(1) == Source)  // It's a store THROUGH the ptr...
-          CandidateStores[Cand->getParent()].push_back(Cand);
-      }
-  }
+  for (Value::use_iterator UI = PointerSource->use_begin(),
+         UE = PointerSource->use_end(); UI != UE; ++UI)
+    if (LoadInst *Cand = dyn_cast<LoadInst>(*UI)) {// Is a load of source?
+      if (Cand->getParent()->getParent() == F &&   // In the same function?
+          Cand != LI && !Cand->isVolatile())       // Not LI itself?
+        CandidateLoads[Cand->getParent()].push_back(Cand);     // Got one...
+    } else if (StoreInst *Cand = dyn_cast<StoreInst>(*UI)) {
+      if (Cand->getParent()->getParent() == F && !Cand->isVolatile() &&
+          Cand->getOperand(1) == PointerSource) // It's a store THROUGH the ptr.
+        CandidateStores[Cand->getParent()].push_back(Cand);
+    }
   
   // Get alias analysis & dominators.
   AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
@@ -358,7 +339,7 @@
     } else if (AllocationInst *AI = dyn_cast<AllocationInst>(I)) {
       // If we run into an allocation of the value being loaded, then the
       // contents are not initialized.
-      if (Allocations.count(AI)) {
+      if ((Value*)AI == PointerSource) {
         LoadInvalidatedInBBBefore = true;
         RetVals.push_back(UndefValue::get(LI->getType()));
         break;






More information about the llvm-commits mailing list