diff options
author | Chad Rosier <mcrosier@codeaurora.org> | 2016-07-08 16:48:40 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@codeaurora.org> | 2016-07-08 16:48:40 +0000 |
commit | 89c32a95318aa2cad998a3ccd721622d9c6c13b5 (patch) | |
tree | 3497c4518161fcac16c36bf10cd30177de32ff15 /llvm/lib/Transforms | |
parent | 647174c8a4ab91ad6a94aa60d56df8b42b97550c (diff) | |
download | bcm5719-llvm-89c32a95318aa2cad998a3ccd721622d9c6c13b5.tar.gz bcm5719-llvm-89c32a95318aa2cad998a3ccd721622d9c6c13b5.zip |
[DSE] Minor refactor based on D21007. NFC.
llvm-svn: 274877
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 89 |
1 files changed, 50 insertions, 39 deletions
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 45e11a50752..7f82596ae54 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -819,6 +819,50 @@ static bool handleEndBlock(BasicBlock &BB, AliasAnalysis *AA, return MadeChange; } +static bool eliminateNoopStore(Instruction *Inst, BasicBlock::iterator &BBI, + AliasAnalysis *AA, MemoryDependenceResults *MD, + const DataLayout &DL, + const TargetLibraryInfo *TLI) { + // Must be a store instruction. + StoreInst *SI = dyn_cast<StoreInst>(Inst); + if (!SI) + return false; + + // If we're storing the same value back to a pointer that we just loaded from, + // then the store can be removed. + if (LoadInst *DepLoad = dyn_cast<LoadInst>(SI->getValueOperand())) { + if (SI->getPointerOperand() == DepLoad->getPointerOperand() && + isRemovable(SI) && memoryIsNotModifiedBetween(DepLoad, SI, AA)) { + + DEBUG(dbgs() << "DSE: Remove Store Of Load from same pointer:\n LOAD: " + << *DepLoad << "\n STORE: " << *SI << '\n'); + + deleteDeadInstruction(SI, &BBI, *MD, *TLI); + ++NumRedundantStores; + return true; + } + } + + // Remove null stores into the calloc'ed objects + Constant *StoredConstant = dyn_cast<Constant>(SI->getValueOperand()); + if (StoredConstant && StoredConstant->isNullValue() && isRemovable(SI)) { + Instruction *UnderlyingPointer = + dyn_cast<Instruction>(GetUnderlyingObject(SI->getPointerOperand(), DL)); + + if (UnderlyingPointer && isCallocLikeFn(UnderlyingPointer, TLI) && + memoryIsNotModifiedBetween(UnderlyingPointer, SI, AA)) { + DEBUG( + dbgs() << "DSE: Remove null store to the calloc'ed object:\n DEAD: " + << *Inst << "\n OBJECT: " << *UnderlyingPointer << '\n'); + + deleteDeadInstruction(SI, &BBI, *MD, *TLI); + ++NumRedundantStores; + return true; + } + } + return false; +} + static bool eliminateDeadStores(BasicBlock &BB, AliasAnalysis *AA, MemoryDependenceResults *MD, DominatorTree *DT, const TargetLibraryInfo *TLI) { @@ -841,50 +885,17 @@ static bool eliminateDeadStores(BasicBlock &BB, AliasAnalysis *AA, Instruction *Inst = &*BBI++; - // If we find something that writes memory, get its memory dependence. + // Check to see if Inst writes to memory. If not, continue. if (!hasMemoryWrite(Inst, *TLI)) continue; - // If we're storing the same value back to a pointer that we just - // loaded from, then the store can be removed. - if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) { - if (LoadInst *DepLoad = dyn_cast<LoadInst>(SI->getValueOperand())) { - if (SI->getPointerOperand() == DepLoad->getPointerOperand() && - isRemovable(SI) && - memoryIsNotModifiedBetween(DepLoad, SI, AA)) { - - DEBUG(dbgs() << "DSE: Remove Store Of Load from same pointer:\n " - << "LOAD: " << *DepLoad << "\n STORE: " << *SI << '\n'); - - deleteDeadInstruction(SI, &BBI, *MD, *TLI); - ++NumRedundantStores; - MadeChange = true; - continue; - } - } - - // Remove null stores into the calloc'ed objects - Constant *StoredConstant = dyn_cast<Constant>(SI->getValueOperand()); - - if (StoredConstant && StoredConstant->isNullValue() && - isRemovable(SI)) { - Instruction *UnderlyingPointer = dyn_cast<Instruction>( - GetUnderlyingObject(SI->getPointerOperand(), DL)); - - if (UnderlyingPointer && isCallocLikeFn(UnderlyingPointer, TLI) && - memoryIsNotModifiedBetween(UnderlyingPointer, SI, AA)) { - DEBUG(dbgs() - << "DSE: Remove null store to the calloc'ed object:\n DEAD: " - << *Inst << "\n OBJECT: " << *UnderlyingPointer << '\n'); - - deleteDeadInstruction(SI, &BBI, *MD, *TLI); - ++NumRedundantStores; - MadeChange = true; - continue; - } - } + // eliminateNoopStore will update in iterator, if necessary. + if (eliminateNoopStore(Inst, BBI, AA, MD, DL, TLI)) { + MadeChange = true; + continue; } + // If we find something that writes memory, get its memory dependence. MemDepResult InstDep = MD->getDependency(Inst); // Ignore any store where we can't find a local dependence. |