[llvm] [LoopDist] Add some runtime checks for cross partition loads (PR #145623)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 03:15:33 PDT 2025
================
@@ -521,6 +521,38 @@ class InstPartitionContainer {
Partition = -1;
}
assert(Partition != -2 && "Pointer not belonging to any partition");
+ // All the store context uses of our address were processed,
+ // Now make sure we don't have cross partition loads.
+ if (RtPtrCheck->Pointers[I].IsWritePtr) {
+ if (Ptr->hasOneUse() || Partition == -1)
+ continue;
+
+ bool ProcessLoads = false;
+ for (auto *U : Ptr->users()) {
+ auto *CurLoad = dyn_cast<LoadInst>(U);
+ if (!CurLoad)
+ continue;
+ if (!L->contains(CurLoad->getParent()))
+ continue;
+
+ ProcessLoads = true;
+ break;
+ }
+
+ if (!ProcessLoads)
+ continue;
+
+ const bool IsWritePtr = false;
+ auto ReadInstructions = LAI.getInstructionsForAccess(Ptr, IsWritePtr);
+ for (Instruction *ReadInst : ReadInstructions) {
+ if (Partition == (int)this->InstToPartitionId[ReadInst])
+ continue;
+
+ // -1 means belonging to multiple partitions.
+ Partition = -1;
+ break;
----------------
Meinersbur wrote:
This should be the same code as for the write case. Consider adding `LAI.getInstructionsForAccess(Ptr, false)` an d `LAI.getInstructionsForAccess(Ptr, true)` into a common list and iterator over it, or wrap this code into a lambda and calling it for each.
The former would be nicer if you changed the signature of `SmallVector<Instruction *, 4>MemoryDepChecker::getInstructionsForAccess(Value *Ptr, bool IsWrite)` to `void getInstructionsForAccess(Value *Ptr, bool IsWrite, SmallVectorImpl<Instruction*> &Result)` so one would reuse the same list. SmallVector's should not be returned anyway.
https://github.com/llvm/llvm-project/pull/145623
More information about the llvm-commits
mailing list