[llvm] LAA: be more precise on different store sizes (PR #122318)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 14:45:59 PST 2025


================
@@ -1989,11 +1990,24 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
     return MemoryDepChecker::Dependence::Unknown;
   }
 
-  uint64_t TypeByteSize = DL.getTypeAllocSize(ATy);
-  bool HasSameSize =
-      DL.getTypeStoreSizeInBits(ATy) == DL.getTypeStoreSizeInBits(BTy);
-  if (!HasSameSize)
-    TypeByteSize = 0;
+  // When the distance is zero, we're reading/writing the same memory location:
+  // check that the store sizes are equal. Otherwise, fail with an unknown
+  // dependence for which we should not generate runtime checks.
+  TypeSize AStoreSz = DL.getTypeStoreSize(ATy),
+           BStoreSz = DL.getTypeStoreSize(BTy);
+  if (Dist->isZero() && AStoreSz != BStoreSz) {
----------------
fhahn wrote:

I think it would be good to be more conservative here and check something like `!SE.isKnownNonZero(Dist)`, as `Dist` could be zero even if it is not a zero constant?

https://github.com/llvm/llvm-project/pull/122318


More information about the llvm-commits mailing list