diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2024-08-13 22:38:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-13 22:38:50 +0800 |
commit | f364b2ee22209e4072c39a153b3385806974f8b0 (patch) | |
tree | 192eb607fa3fec55c1e1e658acce3efef4130df2 /llvm/lib/Analysis/MemoryDependenceAnalysis.cpp | |
parent | f807c5e492878240fe6d7be23b930c78c4e62eba (diff) | |
download | llvm-f364b2ee22209e4072c39a153b3385806974f8b0.zip llvm-f364b2ee22209e4072c39a153b3385806974f8b0.tar.gz llvm-f364b2ee22209e4072c39a153b3385806974f8b0.tar.bz2 |
[LLVM] Don't peek through bitcast on pointers and gep with zero indices. NFC. (#102889)
Since we are using opaque pointers now, we don't need to peek through
bitcast on pointers and gep with zero indices.
Diffstat (limited to 'llvm/lib/Analysis/MemoryDependenceAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/MemoryDependenceAnalysis.cpp | 53 |
1 files changed, 12 insertions, 41 deletions
diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp index 9f7baa9..79504ca 100644 --- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -291,10 +291,6 @@ MemoryDependenceResults::getInvariantGroupPointerDependency(LoadInst *LI, if (isa<GlobalValue>(LoadOperand)) return MemDepResult::getUnknown(); - // Queue to process all pointers that are equivalent to load operand. - SmallVector<const Value *, 8> LoadOperandsQueue; - LoadOperandsQueue.push_back(LoadOperand); - Instruction *ClosestDependency = nullptr; // Order of instructions in uses list is unpredictible. In order to always // get the same result, we will look for the closest dominance. @@ -305,44 +301,19 @@ MemoryDependenceResults::getInvariantGroupPointerDependency(LoadInst *LI, return Best; }; - // FIXME: This loop is O(N^2) because dominates can be O(n) and in worst case - // we will see all the instructions. This should be fixed in MSSA. - while (!LoadOperandsQueue.empty()) { - const Value *Ptr = LoadOperandsQueue.pop_back_val(); - assert(Ptr && !isa<GlobalValue>(Ptr) && - "Null or GlobalValue should not be inserted"); - - for (const Use &Us : Ptr->uses()) { - auto *U = dyn_cast<Instruction>(Us.getUser()); - if (!U || U == LI || !DT.dominates(U, LI)) - continue; - - // Bitcast or gep with zeros are using Ptr. Add to queue to check it's - // users. U = bitcast Ptr - if (isa<BitCastInst>(U)) { - LoadOperandsQueue.push_back(U); - continue; - } - // Gep with zeros is equivalent to bitcast. - // FIXME: we are not sure if some bitcast should be canonicalized to gep 0 - // or gep 0 to bitcast because of SROA, so there are 2 forms. When - // typeless pointers will be ready then both cases will be gone - // (and this BFS also won't be needed). - if (auto *GEP = dyn_cast<GetElementPtrInst>(U)) - if (GEP->hasAllZeroIndices()) { - LoadOperandsQueue.push_back(U); - continue; - } + for (const Use &Us : LoadOperand->uses()) { + auto *U = dyn_cast<Instruction>(Us.getUser()); + if (!U || U == LI || !DT.dominates(U, LI)) + continue; - // If we hit load/store with the same invariant.group metadata (and the - // same pointer operand) we can assume that value pointed by pointer - // operand didn't change. - if ((isa<LoadInst>(U) || - (isa<StoreInst>(U) && - cast<StoreInst>(U)->getPointerOperand() == Ptr)) && - U->hasMetadata(LLVMContext::MD_invariant_group)) - ClosestDependency = GetClosestDependency(ClosestDependency, U); - } + // If we hit load/store with the same invariant.group metadata (and the + // same pointer operand) we can assume that value pointed by pointer + // operand didn't change. + if ((isa<LoadInst>(U) || + (isa<StoreInst>(U) && + cast<StoreInst>(U)->getPointerOperand() == LoadOperand)) && + U->hasMetadata(LLVMContext::MD_invariant_group)) + ClosestDependency = GetClosestDependency(ClosestDependency, U); } if (!ClosestDependency) |