[llvm] r352787 - [MemorySSA] Extend removeMemoryAccess API to optimize MemoryPhis.
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 31 12:13:47 PST 2019
Author: asbirlea
Date: Thu Jan 31 12:13:47 2019
New Revision: 352787
URL: http://llvm.org/viewvc/llvm-project?rev=352787&view=rev
Log:
[MemorySSA] Extend removeMemoryAccess API to optimize MemoryPhis.
Summary:
EarlyCSE needs to optimize MemoryPhis after an access is removed and has
special handling for it. This should be handled by MemorySSA instead.
The default remains that MemoryPhis are *not* optimized after an access
is removed.
Reviewers: george.burgess.iv
Subscribers: sanjoy, jlebar, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D57199
Modified:
llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h
llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp
Modified: llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h?rev=352787&r1=352786&r2=352787&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h Thu Jan 31 12:13:47 2019
@@ -221,14 +221,14 @@ public:
/// associated with it is erased from the program. For example, if a store or
/// load is simply erased (not replaced), removeMemoryAccess should be called
/// on the MemoryAccess for that store/load.
- void removeMemoryAccess(MemoryAccess *);
+ void removeMemoryAccess(MemoryAccess *, bool OptimizePhis = false);
/// Remove MemoryAccess for a given instruction, if a MemoryAccess exists.
/// This should be called when an instruction (load/store) is deleted from
/// the program.
- void removeMemoryAccess(const Instruction *I) {
+ void removeMemoryAccess(const Instruction *I, bool OptimizePhis = false) {
if (MemoryAccess *MA = MSSA->getMemoryAccess(I))
- removeMemoryAccess(MA);
+ removeMemoryAccess(MA, OptimizePhis);
}
/// Remove all MemoryAcceses in a set of BasicBlocks about to be deleted.
Modified: llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp?rev=352787&r1=352786&r2=352787&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp (original)
+++ llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp Thu Jan 31 12:13:47 2019
@@ -1051,7 +1051,7 @@ void MemorySSAUpdater::wireOldPredecesso
}
}
-void MemorySSAUpdater::removeMemoryAccess(MemoryAccess *MA) {
+void MemorySSAUpdater::removeMemoryAccess(MemoryAccess *MA, bool OptimizePhis) {
assert(!MSSA->isLiveOnEntryDef(MA) &&
"Trying to remove the live on entry def");
// We can only delete phi nodes if they have no uses, or we can replace all
@@ -1070,6 +1070,8 @@ void MemorySSAUpdater::removeMemoryAcces
NewDefTarget = cast<MemoryUseOrDef>(MA)->getDefiningAccess();
}
+ SmallSetVector<MemoryPhi *, 4> PhisToCheck;
+
// Re-point the uses at our defining access
if (!isa<MemoryUse>(MA) && !MA->use_empty()) {
// Reset optimized on users of this store, and reset the uses.
@@ -1089,6 +1091,9 @@ void MemorySSAUpdater::removeMemoryAcces
Use &U = *MA->use_begin();
if (auto *MUD = dyn_cast<MemoryUseOrDef>(U.getUser()))
MUD->resetOptimized();
+ if (OptimizePhis)
+ if (MemoryPhi *MP = dyn_cast<MemoryPhi>(U.getUser()))
+ PhisToCheck.insert(MP);
U.set(NewDefTarget);
}
}
@@ -1097,6 +1102,21 @@ void MemorySSAUpdater::removeMemoryAcces
// are doing things here
MSSA->removeFromLookups(MA);
MSSA->removeFromLists(MA);
+
+ // Optionally optimize Phi uses. This will recursively remove trivial phis.
+ if (!PhisToCheck.empty()) {
+ SmallVector<WeakVH, 16> PhisToOptimize{PhisToCheck.begin(),
+ PhisToCheck.end()};
+ PhisToCheck.clear();
+
+ unsigned PhisSize = PhisToOptimize.size();
+ while (PhisSize-- > 0)
+ if (MemoryPhi *MP =
+ cast_or_null<MemoryPhi>(PhisToOptimize.pop_back_val())) {
+ auto OperRange = MP->operands();
+ tryRemoveTrivialPhi(MP, OperRange);
+ }
+ }
}
void MemorySSAUpdater::removeBlocks(
More information about the llvm-commits
mailing list