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

Chris Lattner sabre at nondot.org
Sun Jan 14 22:52:12 PST 2007



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.597 -> 1.598
---
Log message:

delete stores to allocas with one use.  This is a trivial form of DSE which
often kicks in for ?: expressions.


---
Diffs of the changes:  (+18 -0)

 InstructionCombining.cpp |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.597 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.598
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.597	Sun Jan 14 20:27:26 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Mon Jan 15 00:51:56 2007
@@ -8237,6 +8237,24 @@
     ++NumCombined;
     return 0;
   }
+  
+  // If the RHS is an alloca with a single use, zapify the store, making the
+  // alloca dead.
+  if (Ptr->hasOneUse()) {
+    if (isa<AllocaInst>(Ptr)) {
+      EraseInstFromFunction(SI);
+      ++NumCombined;
+      return 0;
+    }
+    
+    if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr))
+      if (isa<AllocaInst>(GEP->getOperand(0)) &&
+          GEP->getOperand(0)->hasOneUse()) {
+        EraseInstFromFunction(SI);
+        ++NumCombined;
+        return 0;
+      }
+  }
 
   // Do really simple DSE, to catch cases where there are several consequtive
   // stores to the same location, separated by a few arithmetic operations. This






More information about the llvm-commits mailing list