From: Owen Anderson Date: Fri, 25 Jan 2008 10:10:33 +0000 (+0000) Subject: DeadStoreElimination can treat byval parameters as if there were alloca's for the... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=e3c36f67580f0963abdf696a26690facb0791ce0;p=oota-llvm.git DeadStoreElimination can treat byval parameters as if there were alloca's for the purpose of removing end-of-function stores. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46351 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 6aa1c63f929..f4b432f88e5 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -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(BBI)) { if (!S->isVolatile()) { @@ -271,8 +268,12 @@ bool DSE::handleEndBlock(BasicBlock& BB, // See through pointer-to-pointer bitcasts TranslatePointerBitCasts(pointerOperand); - if (isa(pointerOperand) && - deadPointers.count(cast(pointerOperand))) { + // Alloca'd pointers or byval arguments (which are functionally like + // alloca's) are valid candidates for removal. + if ( (isa(pointerOperand) && + deadPointers.count(cast(pointerOperand))) || + (isa(pointerOperand) && + cast(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 index 00000000000..08f69a40c57 --- /dev/null +++ b/test/Transforms/DeadStoreElimination/byval.ll @@ -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 +}