diff --git a/llvm/include/llvm/Analysis/MemorySSA.h b/llvm/include/llvm/Analysis/MemorySSA.h --- a/llvm/include/llvm/Analysis/MemorySSA.h +++ b/llvm/include/llvm/Analysis/MemorySSA.h @@ -1202,11 +1202,9 @@ using BaseT = upward_defs_iterator::iterator_facade_base; public: - upward_defs_iterator(const MemoryAccessPair &Info, DominatorTree *DT, - bool *PerformedPhiTranslation = nullptr) + upward_defs_iterator(const MemoryAccessPair &Info, DominatorTree *DT) : DefIterator(Info.first), Location(Info.second), - OriginalAccess(Info.first), DT(DT), - PerformedPhiTranslation(PerformedPhiTranslation) { + OriginalAccess(Info.first), DT(DT) { CurrentPair.first = nullptr; WalkingPhi = Info.first && isa(Info.first); @@ -1270,9 +1268,6 @@ !IsGuaranteedLoopInvariant(TransAddr)) CurrentPair.second = CurrentPair.second.getWithNewSize( LocationSize::beforeOrAfterPointer()); - - if (PerformedPhiTranslation) - *PerformedPhiTranslation = true; } } } @@ -1284,13 +1279,11 @@ MemoryAccess *OriginalAccess = nullptr; DominatorTree *DT = nullptr; bool WalkingPhi = false; - bool *PerformedPhiTranslation = nullptr; }; inline upward_defs_iterator -upward_defs_begin(const MemoryAccessPair &Pair, DominatorTree &DT, - bool *PerformedPhiTranslation = nullptr) { - return upward_defs_iterator(Pair, &DT, PerformedPhiTranslation); +upward_defs_begin(const MemoryAccessPair &Pair, DominatorTree &DT) { + return upward_defs_iterator(Pair, &DT); } inline upward_defs_iterator upward_defs_end() { return upward_defs_iterator(); } diff --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp --- a/llvm/lib/Analysis/MemorySSA.cpp +++ b/llvm/lib/Analysis/MemorySSA.cpp @@ -528,10 +528,6 @@ // List of visited pairs; we can skip paths already // visited with the same memory location. DenseSet VisitedPhis; - // Record if phi translation has been performed during the current phi - // optimization walk, as merging alias results after phi translation can - // yield incorrect results. Context in PR46156. - bool PerformedPhiTranslation = false; /// Find the nearest def or phi that `From` can legally be optimized to. const MemoryAccess *getWalkTarget(const MemoryPhi *From) const { @@ -603,8 +599,7 @@ void addSearches(MemoryPhi *Phi, SmallVectorImpl &PausedSearches, ListIndex PriorNode) { - auto UpwardDefsBegin = upward_defs_begin({Phi, Paths[PriorNode].Loc}, DT, - &PerformedPhiTranslation); + auto UpwardDefsBegin = upward_defs_begin({Phi, Paths[PriorNode].Loc}, DT); auto UpwardDefs = make_range(UpwardDefsBegin, upward_defs_end()); for (const MemoryAccessPair &P : UpwardDefs) { PausedSearches.push_back(Paths.size()); @@ -659,16 +654,8 @@ // - We still cache things for A, so C only needs to walk up a bit. // If this behavior becomes problematic, we can fix without a ton of extra // work. - if (!VisitedPhis.insert({Node.Last, Node.Loc}).second) { - if (PerformedPhiTranslation) { - // If visiting this path performed Phi translation, don't continue, - // since it may not be correct to merge results from two paths if one - // relies on the phi translation. - TerminatedPath Term{Node.Last, PathIndex}; - return Term; - } + if (!VisitedPhis.insert({Node.Last, Node.Loc}).second) continue; - } const MemoryAccess *SkipStopWhere = nullptr; if (Query->SkipSelfAccess && Node.Loc == Query->StartingLoc) { @@ -781,7 +768,7 @@ /// terminates when a MemoryAccess that clobbers said MemoryLocation is found. OptznResult tryOptimizePhi(MemoryPhi *Phi, MemoryAccess *Start, const MemoryLocation &Loc) { - assert(Paths.empty() && VisitedPhis.empty() && !PerformedPhiTranslation && + assert(Paths.empty() && VisitedPhis.empty() && "Reset the optimization state."); Paths.emplace_back(Loc, Start, Phi, None); @@ -937,7 +924,6 @@ void resetPhiOptznState() { Paths.clear(); VisitedPhis.clear(); - PerformedPhiTranslation = false; } public: diff --git a/llvm/test/Analysis/MemorySSA/phi-translation.ll b/llvm/test/Analysis/MemorySSA/phi-translation.ll --- a/llvm/test/Analysis/MemorySSA/phi-translation.ll +++ b/llvm/test/Analysis/MemorySSA/phi-translation.ll @@ -296,7 +296,8 @@ ; CHECK-NEXT: store i16 1, i16* %s1.ptr, align 2 ; CHECK-LABEL: %for.body -; CHECK: ; MemoryUse(4) +; NOLIMIT: ; MemoryUse(1) +; LIMIT: ; MemoryUse(4) ; CHECK-NEXT: %lv = load i16, i16* %arrayidx, align 2 entry: @@ -329,7 +330,8 @@ ; CHECK-NEXT: store i16 1, i16* %s1.ptr, align 2 ; CHECK-LABEL: %for.body -; CHECK: ; MemoryUse(7) +; NOLIMIT: ; MemoryUse(1) +; LIMIT: ; MemoryUse(7) ; CHECK-NEXT: %lv = load i16, i16* %arrayidx, align 2 entry: