[llvm] [LoopInterchange] Improve profitability check for vectorization (PR #133672)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 21 05:35:15 PDT 2025


================
@@ -180,10 +197,22 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
       // Track Output, Flow, and Anti dependencies.
       if (auto D = DI->depends(Src, Dst)) {
         assert(D->isOrdered() && "Expected an output, flow or anti dep.");
+        bool IsForward = true;
+
+        // If Src and Dst are in the same BB, Src is always executed before Dst
+        // in the same loop iteration. If not, we must check whether one BB
+        // dominates the other to determine if Src and Dst are executed in this
+        // order. At the moment, we don't perform such check.
+        if (Src->getParent() != Dst->getParent())
+          IsForward = false;
+
         // If the direction vector is negative, normalize it to
         // make it non-negative.
-        if (D->normalize(SE))
+        bool Normalized = D->normalize(SE);
+        if (Normalized) {
           LLVM_DEBUG(dbgs() << "Negative dependence vector normalized.\n");
+          IsForward = false;
----------------
Meinersbur wrote:

Assuming `>` here means the dependence-vector part of it (since you current encoding puts `*` for backward dependencies): 

An analysis returning `[* >]` is unlikey, but could be possible because pessimizing `[< >]` to `[* >]` should be conservatively correct. It is not reversed though, because `FullDependence::isDirectionNegative` stops at `*`-like dependencies.

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


More information about the llvm-commits mailing list