[llvm] [LAA] Catch load/store to invariant address in dependency checker. (PR #187023)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 26 08:00:29 PDT 2026
================
@@ -2140,9 +2144,15 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
LLVM_DEBUG(dbgs() << "LAA: Src induction step: " << StrideAPtrInt
<< " Sink induction step: " << StrideBPtrInt << "\n");
// At least Src or Sink are loop invariant and the other is strided or
- // invariant. We can generate a runtime check to disambiguate the accesses.
- if (!StrideAPtrInt || !StrideBPtrInt)
+ // invariant.
+ if (!StrideAPtrInt || !StrideBPtrInt) {
+ // If both are loop-invariant and access the same location, we cannot
+ // vectorize.
+ if (!StrideAPtrInt && !StrideBPtrInt && Dist->isZero())
+ return MemoryDepChecker::Dependence::InvariantUnsafe;
+ // Otherwise, we can generate a runtime check to disambiguate the accesses.
----------------
fhahn wrote:
> Yes, I think it would be better to have a single Unsafe kind, as InvariantUnsafe doesn't seem to be an inherently different kind of Unsafe -- I think trading off some loss in LAA debug output is worth the maintainability and clarity we'd get?
It's not 100% clear what extra clarity we would get from a single unsafe kind? It would be less code, but more precise distinction should help with clarity of what kind of dependencies we have and reason about them.
> Hm, I'm not sure if this the complete version of what you wanted to say? Can you kindly explain where we merge accesses with identical SCEVs? I thought MemDepChecker::MemAccessInfo keeps Value pointers? I don't think the following code merges accesses in any way?
Hmm, not sure what happened, sorry for the partial comment.
The issue is not same SCEVs, but same values (e.g. for the phi cases we have a store to %p2, and a load from %phi = [ %p2, ..] , [ %p2, ..].
In the alias set tracker, there will be one entry for %p2 after forked pointer translation, so we end up with a single pointer to check for %p2 in
```
SmallVector<MemAccessInfo, 4> AccessInfos; <<<
for (const Value *ConstPtr : ASPointers) {
Value *Ptr = const_cast<Value *>(ConstPtr);
bool IsWrite = Accesses.contains(MemAccessInfo(Ptr, true));
if (IsWrite)
++NumWritePtrChecks;
else
++NumReadPtrChecks;
AccessInfos.emplace_back(Ptr, IsWrite);
}
```.
Which is why we need to reject those earlier
https://github.com/llvm/llvm-project/pull/187023
More information about the llvm-commits
mailing list