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

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 15 11:18:26 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;
----------------
kasuga-fj wrote:

Okay, I'll add comments.

> 3\. If Src==Dst (e.g two StoreInst of a WAW-dependency), the concept of forward/backward dependency is ill-defined. I think we should optimistically assume a forward dependency
>     3a. dependence vector is positve: `DI->depends(Src, Dst)` probably can only return a positive dependence vector(?) that does not need to be normalized
>     3b. dependence vector is negative: probably cannot happend as discussed (add assertion?)
>     3c. dependence vector is zero: By atomicity of an instruction, cannot happen

I believe 3b cannot happen.

This is a bit of a tangent, but seeing this reminded me of something. Recently, I’ve been thinking that maybe `[* >]` should actually be normalized to `[* <]` (if doing so, I think 3b can happen). If you don’t mind, I'd like to hear what you think about it.

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


More information about the llvm-commits mailing list