Index: include/llvm/Analysis/MemorySSAUpdater.h =================================================================== --- include/llvm/Analysis/MemorySSAUpdater.h +++ include/llvm/Analysis/MemorySSAUpdater.h @@ -261,6 +261,7 @@ MemoryAccess *recursePhi(MemoryAccess *Phi); template MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi, RangeType &Operands); + void tryRemoveTrivialPhis(ArrayRef UpdatedPHIs); void fixupDefs(const SmallVectorImpl &); // Clone all uses and defs from BB to NewBB given a 1:1 map of all // instructions and blocks cloned, and a map of MemoryPhi : Definition Index: lib/Analysis/MemorySSAUpdater.cpp =================================================================== --- lib/Analysis/MemorySSAUpdater.cpp +++ lib/Analysis/MemorySSAUpdater.cpp @@ -355,12 +355,9 @@ } // Optimize potentially non-minimal phis added in this method. - for (unsigned Idx = NewPhiIndex; Idx < NewPhiIndexEnd; ++Idx) { - if (auto *MPhi = cast_or_null(InsertedPHIs[Idx])) { - auto OperRange = MPhi->operands(); - tryRemoveTrivialPhi(MPhi, OperRange); - } - } + int NewPhiSize = NewPhiIndexEnd - NewPhiIndex; + if (NewPhiSize > 0) + tryRemoveTrivialPhis(ArrayRef(&(InsertedPHIs[NewPhiIndex]), NewPhiSize)); // Now that all fixups are done, rename all uses if we are asked. if (RenameUses) { @@ -1215,6 +1212,14 @@ } } +void MemorySSAUpdater::tryRemoveTrivialPhis(ArrayRef UpdatedPHIs) { + for (auto &VH : UpdatedPHIs) + if (auto *MPhi = cast_or_null(VH)) { + auto OperRange = MPhi->operands(); + tryRemoveTrivialPhi(MPhi, OperRange); + } +} + MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB( Instruction *I, MemoryAccess *Definition, const BasicBlock *BB, MemorySSA::InsertionPlace Point) {