Skip to content

Commit

Permalink
Reverting D73027 [DependenceAnalysis] Dependecies for loads marked wi…
Browse files Browse the repository at this point in the history
…th "ivnariant.load" should not be shared with general accesses(PR42151).
  • Loading branch information
ebrevnov committed Feb 14, 2020
1 parent e337fb0 commit cae643d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 229 deletions.
80 changes: 24 additions & 56 deletions llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
Expand Up @@ -902,11 +902,6 @@ MemDepResult MemoryDependenceResults::GetNonLocalInfoForBlock(
Instruction *QueryInst, const MemoryLocation &Loc, bool isLoad,
BasicBlock *BB, NonLocalDepInfo *Cache, unsigned NumSortedEntries) {

bool isInvariantLoad = false;

if (LoadInst *LI = dyn_cast_or_null<LoadInst>(QueryInst))
isInvariantLoad = LI->getMetadata(LLVMContext::MD_invariant_load);

// Do a binary search to see if we already have an entry for this block in
// the cache set. If so, find it.
NonLocalDepInfo::iterator Entry = std::upper_bound(
Expand All @@ -918,13 +913,6 @@ MemDepResult MemoryDependenceResults::GetNonLocalInfoForBlock(
if (Entry != Cache->begin() + NumSortedEntries && Entry->getBB() == BB)
ExistingResult = &*Entry;

// Use cached result for invariant load only if there is no dependency for non
// invariant load. In this case invariant load can not have any dependency as
// well.
if (ExistingResult && isInvariantLoad &&
!ExistingResult->getResult().isNonFuncLocal())
ExistingResult = nullptr;

// If we have a cached entry, and it is non-dirty, use it as the value for
// this dependency.
if (ExistingResult && !ExistingResult->getResult().isDirty()) {
Expand Down Expand Up @@ -953,10 +941,6 @@ MemDepResult MemoryDependenceResults::GetNonLocalInfoForBlock(
MemDepResult Dep =
getPointerDependencyFrom(Loc, isLoad, ScanPos, BB, QueryInst);

// Don't cache results for invariant load.
if (isInvariantLoad)
return Dep;

// If we had a dirty entry for the block, update it. Otherwise, just add
// a new entry.
if (ExistingResult)
Expand Down Expand Up @@ -1045,10 +1029,6 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
InitialNLPI.Size = Loc.Size;
InitialNLPI.AATags = Loc.AATags;

bool isInvariantLoad = false;
if (LoadInst *LI = dyn_cast_or_null<LoadInst>(QueryInst))
isInvariantLoad = LI->getMetadata(LLVMContext::MD_invariant_load);

// Get the NLPI for CacheKey, inserting one into the map if it doesn't
// already have one.
std::pair<CachedNonLocalPointerInfo::iterator, bool> Pair =
Expand All @@ -1057,8 +1037,7 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(

// If we already have a cache entry for this CacheKey, we may need to do some
// work to reconcile the cache entry and the current query.
// Invariant loads don't participate in caching. Thus no need to reconcile.
if (!isInvariantLoad && !Pair.second) {
if (!Pair.second) {
if (CacheInfo->Size != Loc.Size) {
bool ThrowOutEverything;
if (CacheInfo->Size.hasValue() && Loc.Size.hasValue()) {
Expand Down Expand Up @@ -1114,10 +1093,7 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(

// If we have valid cached information for exactly the block we are
// investigating, just return it with no recomputation.
// Don't use cached information for invariant loads since it is valid for
// non-invariant loads only.
if (!isInvariantLoad &&
CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
if (CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
// We have a fully cached result for this query then we can just return the
// cached results and populate the visited set. However, we have to verify
// that we don't already have conflicting results for these blocks. Check
Expand Down Expand Up @@ -1153,18 +1129,14 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
return true;
}

// Invariant loads don't affect cache in any way thus no need to update
// CacheInfo as well.
if (!isInvariantLoad) {
// Otherwise, either this is a new block, a block with an invalid cache
// pointer or one that we're about to invalidate by putting more info into
// it than its valid cache info. If empty, the result will be valid cache
// info, otherwise it isn't.
if (Cache->empty())
CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
else
CacheInfo->Pair = BBSkipFirstBlockPair();
}
// Otherwise, either this is a new block, a block with an invalid cache
// pointer or one that we're about to invalidate by putting more info into it
// than its valid cache info. If empty, the result will be valid cache info,
// otherwise it isn't.
if (Cache->empty())
CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
else
CacheInfo->Pair = BBSkipFirstBlockPair();

SmallVector<BasicBlock *, 32> Worklist;
Worklist.push_back(StartBB);
Expand Down Expand Up @@ -1405,26 +1377,22 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
if (SkipFirstBlock)
return false;

// Results of invariant loads are not cached thus no need to update cached
// information.
if (!isInvariantLoad) {
bool foundBlock = false;
for (NonLocalDepEntry &I : llvm::reverse(*Cache)) {
if (I.getBB() != BB)
continue;
bool foundBlock = false;
for (NonLocalDepEntry &I : llvm::reverse(*Cache)) {
if (I.getBB() != BB)
continue;

assert((GotWorklistLimit || I.getResult().isNonLocal() ||
!DT.isReachableFromEntry(BB)) &&
"Should only be here with transparent block");
foundBlock = true;
I.setResult(MemDepResult::getUnknown());
Result.push_back(
NonLocalDepResult(I.getBB(), I.getResult(), Pointer.getAddr()));
break;
}
(void)foundBlock; (void)GotWorklistLimit;
assert((foundBlock || GotWorklistLimit) && "Current block not in cache?");
assert((GotWorklistLimit || I.getResult().isNonLocal() ||
!DT.isReachableFromEntry(BB)) &&
"Should only be here with transparent block");
foundBlock = true;
I.setResult(MemDepResult::getUnknown());
Result.push_back(
NonLocalDepResult(I.getBB(), I.getResult(), Pointer.getAddr()));
break;
}
(void)foundBlock; (void)GotWorklistLimit;
assert((foundBlock || GotWorklistLimit) && "Current block not in cache?");
}

// Okay, we're done now. If we added new values to the cache, re-sort it.
Expand Down
173 changes: 0 additions & 173 deletions llvm/test/Analysis/MemoryDependenceAnalysis/InvariantLoad.ll

This file was deleted.

0 comments on commit cae643d

Please sign in to comment.