DeadStoreElimination can treat byval parameters as if there were alloca's for the...
authorOwen Anderson <resistor@mac.com>
Fri, 25 Jan 2008 10:10:33 +0000 (10:10 +0000)
committerOwen Anderson <resistor@mac.com>
Fri, 25 Jan 2008 10:10:33 +0000 (10:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46351 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/DeadStoreElimination.cpp
test/Transforms/DeadStoreElimination/byval.ll [new file with mode: 0644]

index 6aa1c63f929a117794d11eff615254eae941cc10..f4b432f88e52b8fc7cd68c24704af41e0ba18b90 100644 (file)
@@ -261,9 +261,6 @@ bool DSE::handleEndBlock(BasicBlock& BB,
   for (BasicBlock::iterator BBI = BB.end(); BBI != BB.begin(); ){
     --BBI;
     
-    if (deadPointers.empty())
-      break;
-    
     // If we find a store whose pointer is dead...
     if (StoreInst* S = dyn_cast<StoreInst>(BBI)) {
       if (!S->isVolatile()) {
@@ -271,8 +268,12 @@ bool DSE::handleEndBlock(BasicBlock& BB,
         // See through pointer-to-pointer bitcasts
         TranslatePointerBitCasts(pointerOperand);
       
-        if (isa<AllocaInst>(pointerOperand) && 
-            deadPointers.count(cast<AllocaInst>(pointerOperand))) {
+        // Alloca'd pointers or byval arguments (which are functionally like
+        // alloca's) are valid candidates for removal.
+        if ( (isa<AllocaInst>(pointerOperand) && 
+              deadPointers.count(cast<AllocaInst>(pointerOperand))) ||
+             (isa<Argument>(pointerOperand) &&
+              cast<Argument>(pointerOperand)->hasByValAttr())) {
           // Remove it!
           MD.removeInstruction(S);
         
diff --git a/test/Transforms/DeadStoreElimination/byval.ll b/test/Transforms/DeadStoreElimination/byval.ll
new file mode 100644 (file)
index 0000000..08f69a4
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | opt -dse | llvm-dis | not grep store
+
+%struct.x = type { i32, i32, i32, i32 }
+
+define i32 @foo(%struct.x* byval  %a) nounwind  {
+entry:
+       %tmp2 = getelementptr %struct.x* %a, i32 0, i32 0
+       store i32 1, i32* %tmp2, align 4
+       ret i32 1
+}