[llvm-commits] CVS: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Feb 3 16:01:02 PST 2004


Changes in directory llvm/lib/Transforms/Utils:

PromoteMemoryToRegister.cpp updated: 1.59 -> 1.60

---
Log message:

Handle extremely trivial cases extremely efficiently.  This speeds up
SRoA/mem2reg from 41.2s to 27.5s on the testcase in PR209.


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

Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff -u llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.59 llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.60
--- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.59	Sun Jan 11 19:18:32 2004
+++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp	Tue Feb  3 16:00:33 2004
@@ -400,25 +400,38 @@
 //
 void PromoteMem2Reg::PromoteLocallyUsedAlloca(AllocaInst *AI) {
   assert(!AI->use_empty() && "There are no uses of the alloca!");
-
-  // Uses of the uninitialized memory location shall get zero...
-  Value *CurVal = Constant::getNullValue(AI->getAllocatedType());
-  
   BasicBlock *BB = cast<Instruction>(AI->use_back())->getParent();
 
-  for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
-    Instruction *Inst = I++;
-    if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
-      if (LI->getOperand(0) == AI) {
-        // Loads just return the "current value"...
-        LI->replaceAllUsesWith(CurVal);
-        BB->getInstList().erase(LI);
-      }
-    } else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
-      if (SI->getOperand(1) == AI) {
-        // Loads just update the "current value"...
-        CurVal = SI->getOperand(0);
-        BB->getInstList().erase(SI);
+
+  // Handle degenerate cases quickly.
+  if (AI->hasOneUse()) {
+    Instruction *U = cast<Instruction>(AI->use_back());
+    if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
+      // Must be a load of uninitialized value.
+      LI->replaceAllUsesWith(Constant::getNullValue(AI->getAllocatedType()));
+    } else {
+      // Otherwise it must be a store which is never read.
+      assert(isa<StoreInst>(U));
+    }
+    BB->getInstList().erase(U);
+  } else {
+    // Uses of the uninitialized memory location shall get zero...
+    Value *CurVal = Constant::getNullValue(AI->getAllocatedType());
+  
+    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
+      Instruction *Inst = I++;
+      if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
+        if (LI->getOperand(0) == AI) {
+          // Loads just return the "current value"...
+          LI->replaceAllUsesWith(CurVal);
+          BB->getInstList().erase(LI);
+        }
+      } else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
+        if (SI->getOperand(1) == AI) {
+          // Loads just update the "current value"...
+          CurVal = SI->getOperand(0);
+          BB->getInstList().erase(SI);
+        }
       }
     }
   }





More information about the llvm-commits mailing list