Skip to content

Commit 2863721

Browse files
committedAug 20, 2019
[MemorySSA] Make Phi cleanups consistent.
Summary: Make Phi cleanups consistent: remove self as a trivial Phi and recurse to potentially remove other trivial phis. Reviewers: george.burgess.iv Subscribers: Prazek, sanjoy.google, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66454 llvm-svn: 369466
1 parent e6c299b commit 2863721

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed
 

‎llvm/include/llvm/Analysis/MemorySSAUpdater.h

+1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ class MemorySSAUpdater {
275275
getPreviousDefRecursive(BasicBlock *,
276276
DenseMap<BasicBlock *, TrackingVH<MemoryAccess>> &);
277277
MemoryAccess *recursePhi(MemoryAccess *Phi);
278+
MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi);
278279
template <class RangeType>
279280
MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi, RangeType &Operands);
280281
void tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs);

‎llvm/lib/Analysis/MemorySSAUpdater.cpp

+17-24
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,9 @@ MemoryAccess *MemorySSAUpdater::recursePhi(MemoryAccess *Phi) {
173173
TrackingVH<MemoryAccess> Res(Phi);
174174
SmallVector<TrackingVH<Value>, 8> Uses;
175175
std::copy(Phi->user_begin(), Phi->user_end(), std::back_inserter(Uses));
176-
for (auto &U : Uses) {
177-
if (MemoryPhi *UsePhi = dyn_cast<MemoryPhi>(&*U)) {
178-
auto OperRange = UsePhi->operands();
179-
tryRemoveTrivialPhi(UsePhi, OperRange);
180-
}
181-
}
176+
for (auto &U : Uses)
177+
if (MemoryPhi *UsePhi = dyn_cast<MemoryPhi>(&*U))
178+
tryRemoveTrivialPhi(UsePhi);
182179
return Res;
183180
}
184181

@@ -187,6 +184,11 @@ MemoryAccess *MemorySSAUpdater::recursePhi(MemoryAccess *Phi) {
187184
// argument.
188185
// IE phi(a, a) or b = phi(a, b) or c = phi(a, a, c)
189186
// We recursively try to remove them.
187+
MemoryAccess *MemorySSAUpdater::tryRemoveTrivialPhi(MemoryPhi *Phi) {
188+
assert(Phi && "Can only remove concrete Phi.");
189+
auto OperRange = Phi->operands();
190+
return tryRemoveTrivialPhi(Phi, OperRange);
191+
}
190192
template <class RangeType>
191193
MemoryAccess *MemorySSAUpdater::tryRemoveTrivialPhi(MemoryPhi *Phi,
192194
RangeType &Operands) {
@@ -490,8 +492,7 @@ void MemorySSAUpdater::fixupDefs(const SmallVectorImpl<WeakVH> &Vars) {
490492
void MemorySSAUpdater::removeEdge(BasicBlock *From, BasicBlock *To) {
491493
if (MemoryPhi *MPhi = MSSA->getMemoryAccess(To)) {
492494
MPhi->unorderedDeleteIncomingBlock(From);
493-
if (MPhi->getNumIncomingValues() == 1)
494-
removeMemoryAccess(MPhi);
495+
tryRemoveTrivialPhi(MPhi);
495496
}
496497
}
497498

@@ -507,8 +508,7 @@ void MemorySSAUpdater::removeDuplicatePhiEdgesBetween(const BasicBlock *From,
507508
Found = true;
508509
return false;
509510
});
510-
if (MPhi->getNumIncomingValues() == 1)
511-
removeMemoryAccess(MPhi);
511+
tryRemoveTrivialPhi(MPhi);
512512
}
513513
}
514514

@@ -617,8 +617,7 @@ void MemorySSAUpdater::updatePhisWhenInsertingUniqueBackedgeBlock(
617617

618618
// If NewMPhi is a trivial phi, remove it. Its use in the header MPhi will be
619619
// replaced with the unique value.
620-
if (HasUniqueIncomingValue)
621-
removeMemoryAccess(NewMPhi);
620+
tryRemoveTrivialPhi(MPhi);
622621
}
623622

624623
void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,
@@ -1227,8 +1226,7 @@ void MemorySSAUpdater::wireOldPredecessorsToNewImmediatePredecessor(
12271226
return false;
12281227
});
12291228
Phi->addIncoming(NewPhi, New);
1230-
if (onlySingleValue(NewPhi))
1231-
removeMemoryAccess(NewPhi);
1229+
tryRemoveTrivialPhi(NewPhi);
12321230
}
12331231
}
12341232

@@ -1293,10 +1291,8 @@ void MemorySSAUpdater::removeMemoryAccess(MemoryAccess *MA, bool OptimizePhis) {
12931291
unsigned PhisSize = PhisToOptimize.size();
12941292
while (PhisSize-- > 0)
12951293
if (MemoryPhi *MP =
1296-
cast_or_null<MemoryPhi>(PhisToOptimize.pop_back_val())) {
1297-
auto OperRange = MP->operands();
1298-
tryRemoveTrivialPhi(MP, OperRange);
1299-
}
1294+
cast_or_null<MemoryPhi>(PhisToOptimize.pop_back_val()))
1295+
tryRemoveTrivialPhi(MP);
13001296
}
13011297
}
13021298

@@ -1310,8 +1306,7 @@ void MemorySSAUpdater::removeBlocks(
13101306
if (!DeadBlocks.count(Succ))
13111307
if (MemoryPhi *MP = MSSA->getMemoryAccess(Succ)) {
13121308
MP->unorderedDeleteIncomingBlock(BB);
1313-
if (MP->getNumIncomingValues() == 1)
1314-
removeMemoryAccess(MP);
1309+
tryRemoveTrivialPhi(MP);
13151310
}
13161311
// Drop all references of all accesses in BB
13171312
if (MemorySSA::AccessList *Acc = MSSA->getWritableBlockAccesses(BB))
@@ -1335,10 +1330,8 @@ void MemorySSAUpdater::removeBlocks(
13351330

13361331
void MemorySSAUpdater::tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs) {
13371332
for (auto &VH : UpdatedPHIs)
1338-
if (auto *MPhi = cast_or_null<MemoryPhi>(VH)) {
1339-
auto OperRange = MPhi->operands();
1340-
tryRemoveTrivialPhi(MPhi, OperRange);
1341-
}
1333+
if (auto *MPhi = cast_or_null<MemoryPhi>(VH))
1334+
tryRemoveTrivialPhi(MPhi);
13421335
}
13431336

13441337
void MemorySSAUpdater::changeToUnreachable(const Instruction *I) {

0 commit comments

Comments
 (0)
Please sign in to comment.