[PATCH] [RFC] Loop Interchane Pass

Karthik Bhat kv.bhat at samsung.com
Mon Feb 9 02:18:25 PST 2015


Hi James,Hal,
Thanks for your inputs. Hal I will move this to llvm commits shortly was working on few issues which i found during testing.
James i tried the example-

   int a = 2;
   for (i=0;i<N;++i) {
    for (j=0;j<M;++j) {
      A[j][i+a] = A[j][i]+1;
    }
  } 

The dependency analysis returns an anti dependecy of [-2 0] between the load and store and we interchange successfully. 
But if add is unknown then i assume it is not safe to interchange as we do not know for sure what dependecy exits.

Dependency Analysis seems to be internally using ScalarEvolution. 
If there is an loop independent variable it is captured using |< symbol.
e.g.
In the matrix multiplication code-

  for(int i=0;i<N;i++)
    for(int j=0;j<M;j++)
      for(int k=0;k<K;k++)
        A[i][j]=A[i][j]+B[i][j]*C[j][k];

we get a dependecy vector of -

  consistent anti [0 0|<]

i.e. the load is independent of inner most iterator (k). So in this case we can move it to outermost as other 2 dependency are 0 (or =) and the code will be vectorize.

The reason I was using this module was because it was giving me the required direction/distance vector/matrix which i can use to decide legality/profitability of interchange.(Based on "Optimizing Compilers for Modern Architectures: A Dependence-Based Approach" by Ken Kennedy)
I think we can use ScalarEvolution to construct the direction/distance matrix as well based on your suggestion but i thought Dependency Analysis already does that for us. I will recheck.

Thanks
Karthik Bhat


http://reviews.llvm.org/D7432

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list