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 @@ -1252,7 +1252,9 @@ // to unknown guarantees that any memory accesses that access locations // after the pointer are considered as clobbers, which is important to // catch loop carried dependences. - if (!IsGuaranteedLoopInvariant(const_cast(Location.Ptr))) + bool GuaranteedLoopInvariant = + IsGuaranteedLoopInvariant(const_cast(Location.Ptr)); + if (!GuaranteedLoopInvariant) CurrentPair.second = Location.getWithNewSize(LocationSize::beforeOrAfterPointer()); PHITransAddr Translator( @@ -1266,6 +1268,10 @@ if (TransAddr != Location.Ptr) { CurrentPair.second = CurrentPair.second.getWithNewPtr(TransAddr); + if (!GuaranteedLoopInvariant && IsGuaranteedLoopInvariant(TransAddr)) + CurrentPair.second = + CurrentPair.second.getWithNewSize(Location.Size); + if (TransAddr && !IsGuaranteedLoopInvariant(const_cast(TransAddr))) CurrentPair.second = CurrentPair.second.getWithNewSize( 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 @@ -437,10 +437,10 @@ ; CHECK-LABEL: merge: ; CHECK: ; 3 = MemoryPhi({lhs,1},{rhs,2}) ; CHECK-NEXT %storemerge2 = phi i32 [ 2, %lhs ], [ 3, %rhs ] -; TODO: Here the defining access could be liveOnEntry. Since all incoming -; values of phi node can be phi translated. -; CHECK: ; MemoryUse(3) -; CHECK-NEXT: %lv = load i16, i16* %arrayidx, align 2 +; LIMIT: ; MemoryUse(3) +; LIMIT-NEXT: %lv = load i16, i16* %arrayidx, align 2 +; NOLIMIT: ; MemoryUse(liveOnEntry) +; NOLIMIT-NEXT: %lv = load i16, i16* %arrayidx, align 2 entry: br i1 %cmp, label %lhs, label %rhs