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

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 23 06:30:42 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:

> Considering this, it makes me wonder if the existence of the function `normalize` might be a bit misleading...

Definitely. When introduced I thought that callers should be able to handle the direction as-is since the caller has chosen `Src` and `Dst`. `normalize` retroactively swaps the arguments. But it also makes some sense since you do not want to call `DA::depends` again with Src/Dst swapped, paying the computational cost again.

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


More information about the llvm-commits mailing list