Make DSE potentially more aggressive by being more specific about alloca sizes.
authorChris Lattner <sabre@nondot.org>
Sun, 28 Nov 2004 20:44:37 +0000 (20:44 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 28 Nov 2004 20:44:37 +0000 (20:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18309 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/DeadStoreElimination.cpp

index c7f3254d4c7728a93799735d8b47b7080b798eb3..27a0b0a881f39074ff02c68b337126da449dc21f 100644 (file)
@@ -16,6 +16,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Transforms/Scalar.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 #include "llvm/Instructions.h"
 #include "llvm/Analysis/AliasAnalysis.h"
@@ -63,13 +64,18 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
   AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
   AliasSetTracker KillLocs(AA);
 
-  // If this block ends in a return, unwind, and eventually tailcall/barrier,
-  // then all allocas are dead at its end.
+  // If this block ends in a return, unwind, unreachable, and eventually
+  // tailcall, then all allocas are dead at its end.
   if (BB.getTerminator()->getNumSuccessors() == 0) {
     BasicBlock *Entry = BB.getParent()->begin();
     for (BasicBlock::iterator I = Entry->begin(), E = Entry->end(); I != E; ++I)
-      if (AllocaInst *AI = dyn_cast<AllocaInst>(I))
-        KillLocs.add(AI, ~0);
+      if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
+        unsigned Size = ~0U;
+        if (!AI->isArrayAllocation() &&
+            AI->getType()->getElementType()->isSized())
+          Size = TD.getTypeSize(AI->getType()->getElementType());
+        KillLocs.add(AI, Size);
+      }
   }
 
   // PotentiallyDeadInsts - Deleting dead stores from the program can make other