@@ -173,12 +173,9 @@ MemoryAccess *MemorySSAUpdater::recursePhi(MemoryAccess *Phi) {
173
173
TrackingVH<MemoryAccess> Res (Phi);
174
174
SmallVector<TrackingVH<Value>, 8 > Uses;
175
175
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);
182
179
return Res;
183
180
}
184
181
@@ -187,6 +184,11 @@ MemoryAccess *MemorySSAUpdater::recursePhi(MemoryAccess *Phi) {
187
184
// argument.
188
185
// IE phi(a, a) or b = phi(a, b) or c = phi(a, a, c)
189
186
// 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
+ }
190
192
template <class RangeType >
191
193
MemoryAccess *MemorySSAUpdater::tryRemoveTrivialPhi (MemoryPhi *Phi,
192
194
RangeType &Operands) {
@@ -490,8 +492,7 @@ void MemorySSAUpdater::fixupDefs(const SmallVectorImpl<WeakVH> &Vars) {
490
492
void MemorySSAUpdater::removeEdge (BasicBlock *From, BasicBlock *To) {
491
493
if (MemoryPhi *MPhi = MSSA->getMemoryAccess (To)) {
492
494
MPhi->unorderedDeleteIncomingBlock (From);
493
- if (MPhi->getNumIncomingValues () == 1 )
494
- removeMemoryAccess (MPhi);
495
+ tryRemoveTrivialPhi (MPhi);
495
496
}
496
497
}
497
498
@@ -507,8 +508,7 @@ void MemorySSAUpdater::removeDuplicatePhiEdgesBetween(const BasicBlock *From,
507
508
Found = true ;
508
509
return false ;
509
510
});
510
- if (MPhi->getNumIncomingValues () == 1 )
511
- removeMemoryAccess (MPhi);
511
+ tryRemoveTrivialPhi (MPhi);
512
512
}
513
513
}
514
514
@@ -617,8 +617,7 @@ void MemorySSAUpdater::updatePhisWhenInsertingUniqueBackedgeBlock(
617
617
618
618
// If NewMPhi is a trivial phi, remove it. Its use in the header MPhi will be
619
619
// replaced with the unique value.
620
- if (HasUniqueIncomingValue)
621
- removeMemoryAccess (NewMPhi);
620
+ tryRemoveTrivialPhi (MPhi);
622
621
}
623
622
624
623
void MemorySSAUpdater::updateForClonedLoop (const LoopBlocksRPO &LoopBlocks,
@@ -1227,8 +1226,7 @@ void MemorySSAUpdater::wireOldPredecessorsToNewImmediatePredecessor(
1227
1226
return false ;
1228
1227
});
1229
1228
Phi->addIncoming (NewPhi, New);
1230
- if (onlySingleValue (NewPhi))
1231
- removeMemoryAccess (NewPhi);
1229
+ tryRemoveTrivialPhi (NewPhi);
1232
1230
}
1233
1231
}
1234
1232
@@ -1293,10 +1291,8 @@ void MemorySSAUpdater::removeMemoryAccess(MemoryAccess *MA, bool OptimizePhis) {
1293
1291
unsigned PhisSize = PhisToOptimize.size ();
1294
1292
while (PhisSize-- > 0 )
1295
1293
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);
1300
1296
}
1301
1297
}
1302
1298
@@ -1310,8 +1306,7 @@ void MemorySSAUpdater::removeBlocks(
1310
1306
if (!DeadBlocks.count (Succ))
1311
1307
if (MemoryPhi *MP = MSSA->getMemoryAccess (Succ)) {
1312
1308
MP->unorderedDeleteIncomingBlock (BB);
1313
- if (MP->getNumIncomingValues () == 1 )
1314
- removeMemoryAccess (MP);
1309
+ tryRemoveTrivialPhi (MP);
1315
1310
}
1316
1311
// Drop all references of all accesses in BB
1317
1312
if (MemorySSA::AccessList *Acc = MSSA->getWritableBlockAccesses (BB))
@@ -1335,10 +1330,8 @@ void MemorySSAUpdater::removeBlocks(
1335
1330
1336
1331
void MemorySSAUpdater::tryRemoveTrivialPhis (ArrayRef<WeakVH> UpdatedPHIs) {
1337
1332
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);
1342
1335
}
1343
1336
1344
1337
void MemorySSAUpdater::changeToUnreachable (const Instruction *I) {
0 commit comments