[PATCH] D90328: Eliminates dead store of an exisiting value
Daniel McCrevan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 28 11:58:41 PDT 2020
dmccrevan created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
dmccrevan requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D90328
Files:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Index: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -2367,6 +2367,46 @@
return false;
}
+ bool eliminateDeadStoresOfExisitingValues() {
+ bool MadeChange = false;
+ LLVM_DEBUG(dbgs() << "Trying to eliminate MemoryDefs that write the "
+ "already exisiting value\n");
+ for (int I = MemDefs.size() - 1; I >= 0; I--) {
+ MemoryDef *Def = MemDefs[I];
+ SmallVector<MemoryAccess *, 4> WorkList;
+ SmallPtrSet<MemoryAccess *, 8> Visited;
+ auto PushMemUses = [&WorkList, &Visited](MemoryAccess *Acc) {
+ if (!Visited.insert(Acc).second)
+ return;
+ for (Use &U : Acc->uses())
+ WorkList.push_back(cast<MemoryAccess>(U.getUser()));
+ };
+ PushMemUses(Def);
+ for (unsigned I = 0; I < WorkList.size(); I++) {
+ if (WorkList.size() >= MemorySSAScanLimit) {
+ LLVM_DEBUG(dbgs() << " ... hit exploration limit.\n");
+ return false;
+ }
+ MemoryAccess *UseAccess = WorkList[I];
+ if (isa<MemoryPhi>(UseAccess))
+ continue;
+
+ Instruction *UseInst = cast<MemoryUseOrDef>(UseAccess)->getMemoryInst();
+ if (MemoryDef *UseDef = dyn_cast<MemoryDef>(UseAccess)) {
+ MemoryAccess *tmp = UseDef->getDefiningAccess();
+ Instruction *tmpi = cast<MemoryUseOrDef>(tmp)->getMemoryInst();
+ if (tmpi->isIdenticalTo(UseInst)) {
+ deleteDeadInstruction(UseInst);
+ MadeChange = true;
+ } else {
+ PushMemUses(UseDef);
+ }
+ }
+ }
+ }
+ return MadeChange;
+ }
+
/// Eliminate writes to objects that are not visible in the caller and are not
/// accessed before returning from the function.
bool eliminateDeadWritesAtEndOfFunction() {
@@ -2632,7 +2672,7 @@
}
}
}
-
+ MadeChange |= State.eliminateDeadStoresOfExisitingValues();
if (EnablePartialOverwriteTracking)
for (auto &KV : State.IOLs)
MadeChange |= removePartiallyOverlappedStores(State.DL, KV.second, TLI);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90328.301363.patch
Type: text/x-patch
Size: 2245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201028/7a606e18/attachment.bin>
More information about the llvm-commits
mailing list