[llvm] [LoopInterchange] Remove 'I' dependency (PR #140709)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 4 04:02:39 PDT 2025


================
@@ -209,8 +209,24 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
             Direction = '*';
           Dep.push_back(Direction);
         }
+
+        // In some cases, the Levels of Dependence may be less than the depth of
+        // the loop nest, particularly when the array's dimension is smaller
+        // than the loop nest depth. In such cases, fill the end of the
+        // direction vector with '*'
+        // TODO: This can be false dependency in some cases, e.g.,
+        //
+        //   for (int i=0; i<N; i++)
+        //     for (int j=0; j<N; j++)
+        //       for (int k=0; k<N; k++)
+        //         v[i] += a[i][j][k];
+        //
+        // In this example, a dependency exists between the load and store of
+        // v[i]. The direction vector returned by DependenceInfo would be [=],
+        // and thus it would become [= * *]. However, if the addition is
+        // associative, exchanging the j-loop and k-loop is legal.
----------------
kasuga-fj wrote:

> DependenceInfo does not consider commutativity (I think that what you mean). If `v` is an array of floats, it wouldn't even be correct without `-ffast-math`.

Yes, that is what I meant, and my comment isn't correct.

> Since determining commutativity is currently not implemented LoopInterchange, the TODO related to this seems misleading.

You're right, I'll delete it.

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


More information about the llvm-commits mailing list