[llvm] [LoopInterchange] Consider forward/backward dependency in vectorize heuristic (PR #133672)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 24 05:26:57 PDT 2025


================
@@ -228,9 +260,47 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
           Dep.push_back('I');
         }
 
+        // Test whether the dependency is forward or not.
+        bool IsKnownForward = true;
+        if (Src->getParent() != Dst->getParent()) {
+          // In general, when Src and Dst are in different BBs, the execution
+          // order of them within a single iteration is not guaranteed. Treat
+          // conservatively as not-forward dependency in this case.
+          IsKnownForward = false;
+        } else {
+          // Src and Dst are in the same BB. If they are the different
+          // instructions, Src should appear before Dst in the BB as they are
+          // stored to MemInstr in that order.
+          assert((Src == Dst || inThisOrder(Src, Dst)) &&
+                 "Unexpected instructions");
+
+          // If the Dependence object is reversed (due to normalization), it
+          // represents the dependency from Dst to Src, meaning it is a backward
+          // dependency. Otherwise it should be a forward dependency.
+          bool IsReversed = D->getSrc() != Src;
+          if (IsReversed)
+            IsKnownForward = false;
+        }
+
+        // Initialize the last element.
----------------
Meinersbur wrote:

```suggestion
        // Initialize the last element. Assume forward dependencies only; it will be updated later if there is any non-forward dependency.
```

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


More information about the llvm-commits mailing list