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
This commit is contained in:
Owen Anderson 2008-01-25 10:10:33 +00:00
parent bc2458408a
commit e3c36f6758
2 changed files with 16 additions and 5 deletions

View 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);

View File

@ -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
}