From c69ace3a64aee6f97bd82f0d811b89f49a3b38ce Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Mon, 4 Feb 2008 04:53:00 +0000 Subject: [PATCH] Be more precise when eliminating pointers bue to memcpy's. This allows more stores to be deleted in some cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46694 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/DeadStoreElimination.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 179dab37fab..f9d1205ada5 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -52,7 +52,7 @@ namespace { Instruction* dependency, SetVector& possiblyDead); bool handleEndBlock(BasicBlock& BB, SetVector& possiblyDead); - bool RemoveUndeadPointers(Value* pointer, + bool RemoveUndeadPointers(Value* pointer, uint64_t killPointerSize, BasicBlock::iterator& BBI, SmallPtrSet& deadPointers, SetVector& possiblyDead); @@ -322,6 +322,7 @@ bool DSE::handleEndBlock(BasicBlock& BB, } Value* killPointer = 0; + uint64_t killPointerSize = ~0UL; // If we encounter a use of the pointer, it is no longer considered dead if (LoadInst* L = dyn_cast(BBI)) { @@ -346,6 +347,11 @@ bool DSE::handleEndBlock(BasicBlock& BB, killPointer = L->getPointerOperand(); } else if (VAArgInst* V = dyn_cast(BBI)) { killPointer = V->getOperand(0); + } else if (isa(BBI) && + isa(cast(BBI)->getLength())) { + killPointer = cast(BBI)->getSource(); + killPointerSize = cast( + cast(BBI)->getLength())->getZExtValue(); } else if (AllocaInst* A = dyn_cast(BBI)) { deadPointers.erase(A); @@ -444,7 +450,7 @@ bool DSE::handleEndBlock(BasicBlock& BB, TranslatePointerBitCasts(killPointer); // Deal with undead pointers - MadeChange |= RemoveUndeadPointers(killPointer, BBI, + MadeChange |= RemoveUndeadPointers(killPointer, killPointerSize, BBI, deadPointers, possiblyDead); } @@ -453,7 +459,7 @@ bool DSE::handleEndBlock(BasicBlock& BB, /// RemoveUndeadPointers - check for uses of a pointer that make it /// undead when scanning for dead stores to alloca's. -bool DSE::RemoveUndeadPointers(Value* killPointer, +bool DSE::RemoveUndeadPointers(Value* killPointer, uint64_t killPointerSize, BasicBlock::iterator& BBI, SmallPtrSet& deadPointers, SetVector& possiblyDead) { @@ -491,7 +497,7 @@ bool DSE::RemoveUndeadPointers(Value* killPointer, // See if this pointer could alias it AliasAnalysis::AliasResult A = AA.alias(*I, pointerSize, - killPointer, ~0U); + killPointer, killPointerSize); // If it must-alias and a store, we can delete it if (isa(BBI) && A == AliasAnalysis::MustAlias) { -- 2.11.0