llvm.org GIT mirror llvm / be044e6
[MemorySSA] Update Phi simplification. When simplifying a Phi to the unique value found incoming, check that there wasn't a Phi already created to break a cycle. If so, remove it. Resolves PR43541. Some additional nits included. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374471 91177308-0d34-0410-b5e6-96231b3b80d8 Alina Sbirlea 1 year, 10 days ago
2 changed file(s) with 62 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
4343 // First, do a cache lookup. Without this cache, certain CFG structures
4444 // (like a series of if statements) take exponential time to visit.
4545 auto Cached = CachedPreviousDef.find(BB);
46 if (Cached != CachedPreviousDef.end()) {
46 if (Cached != CachedPreviousDef.end())
4747 return Cached->second;
48 }
4948
5049 // If this method is called from an unreachable block, return LoE.
5150 if (!MSSA->DT->isReachableFromEntry(BB))
5251 return MSSA->getLiveOnEntryDef();
5352
54 if (BasicBlock *Pred = BB->getSinglePredecessor()) {
53 if (BasicBlock *Pred = BB->getUniquePredecessor()) {
54 VisitedBlocks.insert(BB);
5555 // Single predecessor case, just recurse, we can only have one definition.
5656 MemoryAccess *Result = getPreviousDefFromEnd(Pred, CachedPreviousDef);
5757 CachedPreviousDef.insert({BB, Result});
9595 // See if we can avoid the phi by simplifying it.
9696 auto *Result = tryRemoveTrivialPhi(Phi, PhiOps);
9797 // If we couldn't simplify, we may have to create a phi
98 if (Result == Phi && UniqueIncomingAccess && SingleAccess)
98 if (Result == Phi && UniqueIncomingAccess && SingleAccess) {
99 // A concrete Phi only exists if we created an empty one to break a cycle.
100 if (Phi) {
101 assert(Phi->operands().empty() && "Expected empty Phi");
102 Phi->replaceAllUsesWith(SingleAccess);
103 removeMemoryAccess(Phi);
104 }
99105 Result = SingleAccess;
100 else if (Result == Phi && !(UniqueIncomingAccess && SingleAccess)) {
106 } else if (Result == Phi && !(UniqueIncomingAccess && SingleAccess)) {
101107 if (!Phi)
102108 Phi = MSSA->createMemoryPhi(BB);
103109
236242 void MemorySSAUpdater::insertUse(MemoryUse *MU, bool RenameUses) {
237243 InsertedPHIs.clear();
238244 MU->setDefiningAccess(getPreviousDef(MU));
245
239246 // In cases without unreachable blocks, because uses do not create new
240247 // may-defs, there are only two cases:
241248 // 1. There was a def already below us, and therefore, we should not have
0 ; RUN: opt -gvn-hoist -enable-mssa-loop-dependency -S < %s | FileCheck %s
1 ; REQUIRES: asserts
2 %struct.job_pool.6.7 = type { i32 }
3
4 ; CHECK-LABEL: @f()
5 define dso_local void @f() {
6 entry:
7 br label %for.cond
8
9 for.cond: ; preds = %for.end, %entry
10 br label %for.body
11
12 for.body: ; preds = %for.cond
13 br label %if.end
14
15 if.then: ; No predecessors!
16 br label %if.end
17
18 if.end: ; preds = %if.then, %for.body
19 br i1 false, label %for.body12.lr.ph, label %for.end
20
21 for.body12.lr.ph: ; preds = %if.end
22 br label %for.body12
23
24 for.body12: ; preds = %if.end40, %for.body12.lr.ph
25 br label %if.then23
26
27 if.then23: ; preds = %for.body12
28 br i1 undef, label %if.then24, label %if.else
29
30 if.then24: ; preds = %if.then23
31 %0 = load %struct.job_pool.6.7*, %struct.job_pool.6.7** undef, align 8
32 br label %if.end40
33
34 if.else: ; preds = %if.then23
35 %1 = load %struct.job_pool.6.7*, %struct.job_pool.6.7** undef, align 8
36 br label %if.end40
37
38 if.end40: ; preds = %if.else, %if.then24
39 br i1 false, label %for.body12, label %for.cond9.for.end_crit_edge
40
41 for.cond9.for.end_crit_edge: ; preds = %if.end40
42 br label %for.end
43
44 for.end: ; preds = %for.cond9.for.end_crit_edge, %if.end
45 br i1 true, label %if.then45, label %for.cond
46
47 if.then45: ; preds = %for.end
48 ret void
49 }