llvm.org GIT mirror llvm / ff0b826
[MemorySSA] Update Phi insertion. Summary: MemoryPhis may be needed following a Def insertion inthe IDF of all the new accesses added (phis + potentially a def). Ensure this also occurs when only the new MemoryPhis are the defining accesses. Note: The need for computing IDF here is because of new Phis added with edges incoming from unreachable code, Phis that had previously been simplified. The preferred solution is to not reintroduce such Phis. This patch is the needed fix while working on the preferred solution. Reviewers: george.burgess.iv Subscribers: Prazek, sanjoy.google, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67927 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372673 91177308-0d34-0410-b5e6-96231b3b80d8 Alina Sbirlea 1 year, 27 days ago
2 changed file(s) with 73 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
312312 // and that def is now our defining access.
313313 MD->setDefiningAccess(DefBefore);
314314
315 // Remember the index where we may insert new phis below.
316 unsigned NewPhiIndex = InsertedPHIs.size();
317
318315 SmallVector FixupList(InsertedPHIs.begin(), InsertedPHIs.end());
316
317 SmallPtrSet DefiningBlocks;
318
319319 if (!DefBeforeSameBlock) {
320320 // If there was a local def before us, we must have the same effect it
321321 // did. Because every may-def is the same, any phis/etc we would create, it
334334 auto Iter = MD->getDefsIterator();
335335 ++Iter;
336336 auto IterEnd = MSSA->getBlockDefs(MD->getBlock())->end();
337 if (Iter == IterEnd) {
338 ForwardIDFCalculator IDFs(*MSSA->DT);
339 SmallVector IDFBlocks;
340 SmallPtrSet DefiningBlocks;
341 for (const auto &VH : InsertedPHIs)
342 if (const auto *RealPHI = cast_or_null(VH))
343 DefiningBlocks.insert(RealPHI->getBlock());
337 if (Iter == IterEnd)
344338 DefiningBlocks.insert(MD->getBlock());
345 IDFs.setDefiningBlocks(DefiningBlocks);
346 IDFs.calculate(IDFBlocks);
347 SmallVector, 4> NewInsertedPHIs;
348 for (auto *BBIDF : IDFBlocks) {
349 auto *MPhi = MSSA->getMemoryAccess(BBIDF);
350 if (!MPhi) {
351 MPhi = MSSA->createMemoryPhi(BBIDF);
352 NewInsertedPHIs.push_back(MPhi);
353 }
354 // Add the phis created into the IDF blocks to NonOptPhis, so they are
355 // not optimized out as trivial by the call to getPreviousDefFromEnd
356 // below. Once they are complete, all these Phis are added to the
357 // FixupList, and removed from NonOptPhis inside fixupDefs().
358 // Existing Phis in IDF may need fixing as well, and potentially be
359 // trivial before this insertion, hence add all IDF Phis. See PR43044.
360 NonOptPhis.insert(MPhi);
361 }
362
363 for (auto &MPhi : NewInsertedPHIs) {
364 auto *BBIDF = MPhi->getBlock();
365 for (auto *Pred : predecessors(BBIDF)) {
366 DenseMap> CachedPreviousDef;
367 MPhi->addIncoming(getPreviousDefFromEnd(Pred, CachedPreviousDef),
368 Pred);
369 }
370 }
371
372 // Re-take the index where we're adding the new phis, because the above
373 // call to getPreviousDefFromEnd, may have inserted into InsertedPHIs.
374 NewPhiIndex = InsertedPHIs.size();
375 for (auto &MPhi : NewInsertedPHIs) {
376 InsertedPHIs.push_back(&*MPhi);
377 FixupList.push_back(&*MPhi);
378 }
379 }
380339
381340 FixupList.push_back(MD);
382341 }
383342
343 ForwardIDFCalculator IDFs(*MSSA->DT);
344 SmallVector IDFBlocks;
345 for (const auto &VH : InsertedPHIs)
346 if (const auto *RealPHI = cast_or_null(VH))
347 DefiningBlocks.insert(RealPHI->getBlock());
348 IDFs.setDefiningBlocks(DefiningBlocks);
349 IDFs.calculate(IDFBlocks);
350 SmallVector, 4> NewInsertedPHIs;
351 for (auto *BBIDF : IDFBlocks) {
352 auto *MPhi = MSSA->getMemoryAccess(BBIDF);
353 if (!MPhi) {
354 MPhi = MSSA->createMemoryPhi(BBIDF);
355 NewInsertedPHIs.push_back(MPhi);
356 }
357 // Add the phis created into the IDF blocks to NonOptPhis, so they are not
358 // optimized out as trivial by the call to getPreviousDefFromEnd below. Once
359 // they are complete, all these Phis are added to the FixupList, and removed
360 // from NonOptPhis inside fixupDefs(). Existing Phis in IDF may need fixing
361 // as well, and potentially be trivial before this insertion, hence add all
362 // IDF Phis. See PR43044.
363 NonOptPhis.insert(MPhi);
364 }
365
366 for (auto &MPhi : NewInsertedPHIs) {
367 auto *BBIDF = MPhi->getBlock();
368 for (auto *Pred : predecessors(BBIDF)) {
369 DenseMap> CachedPreviousDef;
370 MPhi->addIncoming(getPreviousDefFromEnd(Pred, CachedPreviousDef), Pred);
371 }
372 }
373
374 // Remember the index where we may insert new phis.
375 unsigned NewPhiIndex = InsertedPHIs.size();
376 for (auto &MPhi : NewInsertedPHIs) {
377 InsertedPHIs.push_back(&*MPhi);
378 FixupList.push_back(&*MPhi);
379 }
384380 // Remember the index where we stopped inserting new phis above, since the
385381 // fixupDefs call in the loop below may insert more, that are already minimal.
386382 unsigned NewPhiIndexEnd = InsertedPHIs.size();
0 ; RUN: opt -S -licm -enable-mssa-loop-dependency=true < %s | FileCheck %s
1 ; REQUIRES: asserts
2 @v_274 = external dso_local global i64, align 1
3 @v_295 = external dso_local global i16, align 1
4 @v_335 = external dso_local global i32, align 1
5
6 ; CHECK-LABEL: @main()
7 define dso_local void @main() {
8 entry:
9 store i32 undef, i32* @v_335, align 1
10 br i1 undef, label %gate, label %exit
11
12 nopredentry1: ; No predecessors!
13 br label %preinfiniteloop
14
15 nopredentry2: ; No predecessors!
16 br label %gate
17
18 gate: ; preds = %nopredentry2, %entry
19 br i1 undef, label %preinfiniteloop, label %exit
20
21 preinfiniteloop: ; preds = %gate, %nopredentry1
22 br label %infiniteloop
23
24 infiniteloop: ; preds = %infiniteloop, %preinfiniteloop
25 store i16 undef, i16* @v_295, align 1
26 br label %infiniteloop
27
28 exit: ; preds = %gate, %entry
29 store i64 undef, i64* @v_274, align 1
30 ret void
31 }