diff options
-rw-r--r-- | lib/Transforms/Scalar/DeadStoreElimination.cpp | 11 | ||||
-rw-r--r-- | test/Transforms/DeadStoreElimination/byval.ll | 10 |
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 6aa1c63f92..f4b432f88e 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<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 index 0000000000..08f69a40c5 --- /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 +} |