diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -363,14 +363,11 @@ // place, compute IDF and place phis. SmallPtrSet DefiningBlocks; - // If this is the last Def in the block, also compute IDF based on MD, since - // this may a new Def added, and we may need additional Phis. - auto Iter = MD->getDefsIterator(); - ++Iter; - auto IterEnd = MSSA->getBlockDefs(MD->getBlock())->end(); - if (Iter == IterEnd) - DefiningBlocks.insert(MD->getBlock()); - + // If this is the last Def in the block, we may need additional Phis. + // Compute IDF in all cases, as renaming needs to be done even when MD is + // not the last access, because it can introduce a new access past which a + // previous access was optimized; that access needs to be reoptimized. + DefiningBlocks.insert(MD->getBlock()); for (const auto &VH : InsertedPHIs) if (const auto *RealPHI = cast_or_null(VH)) DefiningBlocks.insert(RealPHI->getBlock());