Skip to content

Commit d516377

Browse files
committed
[LoopDist] Add some runtime checks for cross partition loads - p2
Add back in getInstructionsForAccess as query for Instructions modifying memory to mark cross partition accesses.
1 parent ab696fb commit d516377

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,12 +2404,14 @@ bool MemoryDepChecker::areDepsSafe(const DepCandidates &DepCands,
24042404
SmallVector<Instruction *, 4>
24052405
MemoryDepChecker::getInstructionsForAccess(Value *Ptr, bool IsWrite) const {
24062406
MemAccessInfo Access(Ptr, IsWrite);
2407-
auto &IndexVector = Accesses.find(Access)->second;
2408-
2407+
auto I = Accesses.find(Access);
24092408
SmallVector<Instruction *, 4> Insts;
2410-
transform(IndexVector,
2411-
std::back_inserter(Insts),
2412-
[&](unsigned Idx) { return this->InstMap[Idx]; });
2409+
if (I != Accesses.end()) {
2410+
transform(I->second,
2411+
std::back_inserter(Insts),
2412+
[&](unsigned Idx) { return this->InstMap[Idx]; });
2413+
}
2414+
24132415
return Insts;
24142416
}
24152417

llvm/lib/Transforms/Scalar/LoopDistribute.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,10 @@ class InstPartitionContainer {
502502
SmallVector<int, 8> PtrToPartitions(N);
503503
for (unsigned I = 0; I < N; ++I) {
504504
Value *Ptr = RtPtrCheck->Pointers[I].PointerValue;
505-
auto Instructions =
506-
LAI.getInstructionsForAccess(Ptr, RtPtrCheck->Pointers[I].IsWritePtr);
505+
auto Instructions = LAI.getInstructionsForAccess(Ptr, /* IsWrite */ true);
506+
auto ReadInstructions =
507+
LAI.getInstructionsForAccess(Ptr, /* IsWrite */ false);
508+
Instructions.append(ReadInstructions.begin(), ReadInstructions.end());
507509

508510
int &Partition = PtrToPartitions[I];
509511
// First set it to uninitialized.
@@ -521,21 +523,6 @@ class InstPartitionContainer {
521523
Partition = -1;
522524
}
523525
assert(Partition != -2 && "Pointer not belonging to any partition");
524-
// All the store context uses of our address were processed,
525-
// Now make sure we don't have cross partition loads.
526-
if (RtPtrCheck->Pointers[I].IsWritePtr) {
527-
if (Ptr->hasOneUse() || Partition == -1)
528-
continue;
529-
530-
for (User *U : Ptr->users())
531-
if (auto *CurLoad = dyn_cast<LoadInst>(U))
532-
if (L->contains(CurLoad->getParent()))
533-
if (Partition != (int)this->InstToPartitionId[CurLoad]) {
534-
// -1 means belonging to multiple partitions.
535-
Partition = -1;
536-
break;
537-
}
538-
}
539526
}
540527

541528
return PtrToPartitions;

0 commit comments

Comments
 (0)