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 @@ -1245,31 +1245,24 @@ CurrentPair.first = *DefIterator; CurrentPair.second = Location; if (WalkingPhi && Location.Ptr) { - // Mark size as unknown, if the location is not guaranteed to be - // loop-invariant for any possible loop in the function. Setting the size - // 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(Location.Ptr)) - CurrentPair.second = - Location.getWithNewSize(LocationSize::beforeOrAfterPointer()); PHITransAddr Translator( const_cast(Location.Ptr), OriginalAccess->getBlock()->getModule()->getDataLayout(), nullptr); if (!Translator.PHITranslateValue(OriginalAccess->getBlock(), - DefIterator.getPhiArgBlock(), DT, - true)) { - Value *TransAddr = Translator.getAddr(); - if (TransAddr != Location.Ptr) { - CurrentPair.second = CurrentPair.second.getWithNewPtr(TransAddr); - - if (TransAddr && - !IsGuaranteedLoopInvariant(TransAddr)) - CurrentPair.second = CurrentPair.second.getWithNewSize( - LocationSize::beforeOrAfterPointer()); - } - } + DefIterator.getPhiArgBlock(), DT, true)) + if (Translator.getAddr() != CurrentPair.second.Ptr) + CurrentPair.second = + CurrentPair.second.getWithNewPtr(Translator.getAddr()); + + // Mark size as unknown, if the location is not guaranteed to be + // loop-invariant for any possible loop in the function. Setting the size + // 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(CurrentPair.second.Ptr)) + CurrentPair.second = CurrentPair.second.getWithNewSize( + LocationSize::beforeOrAfterPointer()); } } 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 @@ -439,10 +439,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