delete stores to allocas with one use. This is a trivial form of DSE which
authorChris Lattner <sabre@nondot.org>
Mon, 15 Jan 2007 06:51:56 +0000 (06:51 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 15 Jan 2007 06:51:56 +0000 (06:51 +0000)
often kicks in for ?: expressions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33231 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index f961ac25e9518b65b03d75bff89e64c85e666d9d..dc0713804351c0684e72dd424450c83e9a5da1bc 100644 (file)
@@ -8237,6 +8237,24 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
     ++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