[llvm] [LAA] Add initial support for non-power-of-2 store-load forwarding distance (PR #137873)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 1 03:43:28 PDT 2025


================
@@ -1831,24 +1832,61 @@ bool MemoryDepChecker::couldPreventStoreLoadForward(uint64_t Distance,
       break;
     }
   }
+  // If target supports active vector length, then it supports non-power-2
+  // vector factor. So, we iterate in a backward order to find largest VF, which
+  // allows aligned stores-loads or the number of iterations between conflicting
+  // memory addresses is not less than 8 (NumItersForStoreLoadThroughMemory).
+  if (AllowNonPow2Deps) {
+    MaxVFWithoutSLForwardIssuesNonPowerOf2 =
+        std::min(8 * VectorizerParams::MaxVectorWidth / TypeByteSize,
+                 MaxNonPowerOf2StoreLoadForwardSafeDistanceInBits);
+
+    for (uint64_t VF = MaxVFWithoutSLForwardIssuesNonPowerOf2;
+         VF > MaxVFWithoutSLForwardIssuesPowerOf2; VF -= TypeByteSize) {
+      if (Distance % VF == 0 ||
+          Distance / VF >= NumItersForStoreLoadThroughMemory) {
+        uint64_t GCD =
+            isSafeForAnyStoreLoadForwardDistances()
----------------
fhahn wrote:

this is invariant, right? Can hoist out?

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


More information about the llvm-commits mailing list