From: Owen Anderson Date: Fri, 13 Jul 2007 18:26:26 +0000 (+0000) Subject: Be more aggressive in removing dead stores, and in removing instructions trivially... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3e8d0017996aeb08c5190b6b6d83f0a717526ab5;p=oota-llvm.git Be more aggressive in removing dead stores, and in removing instructions trivially dead after DSE. This drastically improves the effect of FastDSE on kimwitu++. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@39819 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/FastDSE.cpp b/lib/Transforms/Scalar/FastDSE.cpp index 7794953e432..13e61366477 100644 --- a/lib/Transforms/Scalar/FastDSE.cpp +++ b/lib/Transforms/Scalar/FastDSE.cpp @@ -56,6 +56,14 @@ namespace { SetVector& possiblyDead); void DeleteDeadInstructionChains(Instruction *I, SetVector &DeadInsts); + void TranslatePointerBitCasts(Value*& v) { + assert(isa(v->getType()) && "Translating a non-pointer type?"); + + // See through pointer-to-pointer bitcasts + while (BitCastInst* C = dyn_cast(v)) + if (isa(C->getSrcTy())) + v = C->getOperand(0); + } // getAnalysisUsage - We require post dominance frontiers (aka Control // Dependence Graph) @@ -93,6 +101,7 @@ bool FDSE::runOnBasicBlock(BasicBlock &BB) { pointer = S->getPointerOperand(); else if (FreeInst* F = dyn_cast(BBI)) pointer = F->getPointerOperand(); + assert(pointer && "Not a free or a store?"); StoreInst*& last = lastStore[pointer]; @@ -110,6 +119,8 @@ bool FDSE::runOnBasicBlock(BasicBlock &BB) { // DCE instructions only used to calculate that store if (Instruction* D = dyn_cast(last->getOperand(0))) possiblyDead.insert(D); + if (Instruction* D = dyn_cast(last->getOperand(1))) + possiblyDead.insert(D); last->eraseFromParent(); NumFastStores++; @@ -165,7 +176,7 @@ bool FDSE::handleFreeWithNonTrivialDependency(FreeInst* F, Instruction* dep, Value* depPointer = dependency->getPointerOperand(); unsigned depPointerSize = TD.getTypeSize(dependency->getOperand(0)->getType()); - + // Check for aliasing AliasAnalysis::AliasResult A = AA.alias(F->getPointerOperand(), ~0UL, depPointer, depPointerSize); @@ -177,6 +188,8 @@ bool FDSE::handleFreeWithNonTrivialDependency(FreeInst* F, Instruction* dep, // DCE instructions only used to calculate that store if (Instruction* D = dyn_cast(dependency->getOperand(0))) possiblyDead.insert(D); + if (Instruction* D = dyn_cast(dependency->getOperand(1))) + possiblyDead.insert(D); dependency->eraseFromParent(); NumFastStores++; @@ -216,23 +229,24 @@ bool FDSE::handleEndBlock(BasicBlock& BB, SetVector& possiblyDead) // If we find a store whose pointer is dead... if (StoreInst* S = dyn_cast(BBI)) { - if (deadPointers.count(S->getPointerOperand())){ + Value* pointerOperand = S->getPointerOperand(); + // See through pointer-to-pointer bitcasts + TranslatePointerBitCasts(pointerOperand); + + if (deadPointers.count(pointerOperand)){ // Remove it! MD.removeInstruction(S); // DCE instructions only used to calculate that store if (Instruction* D = dyn_cast(S->getOperand(0))) possiblyDead.insert(D); + if (Instruction* D = dyn_cast(S->getOperand(1))) + possiblyDead.insert(D); BBI++; S->eraseFromParent(); NumFastStores++; MadeChange = true; - - // If we can't trivially delete this store, consider it undead - } else { - killPointer = S->getPointerOperand(); - killPointerSize = TD.getTypeSize(S->getOperand(0)->getType()); } // If we encounter a use of the pointer, it is no longer considered dead @@ -261,7 +275,7 @@ bool FDSE::handleEndBlock(BasicBlock& BB, SetVector& possiblyDead) // See if the call site touches it AliasAnalysis::ModRefResult A = AA.getModRefInfo(CallSite::get(BBI), *I, pointerSize); - if (A != AliasAnalysis::NoModRef) + if (A == AliasAnalysis::ModRef || A == AliasAnalysis::Ref) dead.push_back(*I); } @@ -315,6 +329,8 @@ bool FDSE::RemoveUndeadPointers(Value* killPointer, unsigned killPointerSize, // DCE instructions only used to calculate that store if (Instruction* D = dyn_cast(S->getOperand(0))) possiblyDead.insert(D); + if (Instruction* D = dyn_cast(S->getOperand(1))) + possiblyDead.insert(D); BBI++; S->eraseFromParent();