summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/MemorySSAUpdater.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/MemorySSAUpdater.cpp')
-rw-r--r--llvm/lib/Analysis/MemorySSAUpdater.cpp77
1 files changed, 40 insertions, 37 deletions
diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp
index 6018968c199..d103c3a8b83 100644
--- a/llvm/lib/Analysis/MemorySSAUpdater.cpp
+++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp
@@ -347,51 +347,54 @@ void MemorySSAUpdater::insertDef(MemoryDef *MD, bool RenameUses) {
// If this is the first def in the block and this insert is in an arbitrary
// place, compute IDF and place phis.
+ SmallPtrSet<BasicBlock *, 2> 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) {
- SmallPtrSet<BasicBlock *, 2> DefiningBlocks;
+ if (Iter == IterEnd)
DefiningBlocks.insert(MD->getBlock());
- for (const auto &VH : InsertedPHIs)
- if (const auto *RealPHI = cast_or_null<MemoryPhi>(VH))
- DefiningBlocks.insert(RealPHI->getBlock());
- ForwardIDFCalculator IDFs(*MSSA->DT);
- SmallVector<BasicBlock *, 32> IDFBlocks;
- IDFs.setDefiningBlocks(DefiningBlocks);
- IDFs.calculate(IDFBlocks);
- SmallVector<AssertingVH<MemoryPhi>, 4> NewInsertedPHIs;
- for (auto *BBIDF : IDFBlocks) {
- auto *MPhi = MSSA->getMemoryAccess(BBIDF);
- if (!MPhi) {
- MPhi = MSSA->createMemoryPhi(BBIDF);
- NewInsertedPHIs.push_back(MPhi);
- }
- // Add the phis created into the IDF blocks to NonOptPhis, so they are
- // not optimized out as trivial by the call to getPreviousDefFromEnd
- // below. Once they are complete, all these Phis are added to the
- // FixupList, and removed from NonOptPhis inside fixupDefs(). Existing
- // Phis in IDF may need fixing as well, and potentially be trivial
- // before this insertion, hence add all IDF Phis. See PR43044.
- NonOptPhis.insert(MPhi);
+
+ for (const auto &VH : InsertedPHIs)
+ if (const auto *RealPHI = cast_or_null<MemoryPhi>(VH))
+ DefiningBlocks.insert(RealPHI->getBlock());
+ ForwardIDFCalculator IDFs(*MSSA->DT);
+ SmallVector<BasicBlock *, 32> IDFBlocks;
+ IDFs.setDefiningBlocks(DefiningBlocks);
+ IDFs.calculate(IDFBlocks);
+ SmallVector<AssertingVH<MemoryPhi>, 4> NewInsertedPHIs;
+ for (auto *BBIDF : IDFBlocks) {
+ auto *MPhi = MSSA->getMemoryAccess(BBIDF);
+ if (!MPhi) {
+ MPhi = MSSA->createMemoryPhi(BBIDF);
+ NewInsertedPHIs.push_back(MPhi);
}
- for (auto &MPhi : NewInsertedPHIs) {
- auto *BBIDF = MPhi->getBlock();
- for (auto *Pred : predecessors(BBIDF)) {
- DenseMap<BasicBlock *, TrackingVH<MemoryAccess>> CachedPreviousDef;
- MPhi->addIncoming(getPreviousDefFromEnd(Pred, CachedPreviousDef),
- Pred);
- }
+ // Add the phis created into the IDF blocks to NonOptPhis, so they are not
+ // optimized out as trivial by the call to getPreviousDefFromEnd below.
+ // Once they are complete, all these Phis are added to the FixupList, and
+ // removed from NonOptPhis inside fixupDefs(). Existing Phis in IDF may
+ // need fixing as well, and potentially be trivial before this insertion,
+ // hence add all IDF Phis. See PR43044.
+ NonOptPhis.insert(MPhi);
+ }
+ for (auto &MPhi : NewInsertedPHIs) {
+ auto *BBIDF = MPhi->getBlock();
+ for (auto *Pred : predecessors(BBIDF)) {
+ DenseMap<BasicBlock *, TrackingVH<MemoryAccess>> CachedPreviousDef;
+ MPhi->addIncoming(getPreviousDefFromEnd(Pred, CachedPreviousDef), Pred);
}
+ }
- // Re-take the index where we're adding the new phis, because the above
- // call to getPreviousDefFromEnd, may have inserted into InsertedPHIs.
- NewPhiIndex = InsertedPHIs.size();
- for (auto &MPhi : NewInsertedPHIs) {
- InsertedPHIs.push_back(&*MPhi);
- FixupList.push_back(&*MPhi);
- }
+ // Re-take the index where we're adding the new phis, because the above call
+ // to getPreviousDefFromEnd, may have inserted into InsertedPHIs.
+ NewPhiIndex = InsertedPHIs.size();
+ for (auto &MPhi : NewInsertedPHIs) {
+ InsertedPHIs.push_back(&*MPhi);
+ FixupList.push_back(&*MPhi);
}
+
FixupList.push_back(MD);
}
OpenPOWER on IntegriCloud