[llvm-dev] LoopVectorize fails to vectorize more complex loops

Alex Susu via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 6 17:52:00 PDT 2018


   Hello.
     Could you please tell me why the first loop of the following program (also maybe the 
commented loop) doesn't get vectorized with LoopVectorize (from a recent LLVM build from 
the SVN repository from Jun 2018)?

typedef short TYPE;
TYPE data[1400][1200];

void kernel_covariance(int m, int n, TYPE mean[1200]) {
   int i, j, k;

   for (j = 0; j < m; j++)
     {
       mean[j] = 0.0;
       for (i = 0; i < n; i++)
         mean[j] += data[j][i];
       //mean[j] /= float_n;
     }

   // This loop gets vectorized
   for (i = 0; i < n; i++)
     for (j = 0; j < m; j++)
       data[i][j] -= mean[j];

   /*
   // This loop doesn't get vectorized either:
   for (i = 0; i < m; i++)
     for (j = i; j < m; j++)
       {
         cov[i][j] = 0.0;
         for (k = 0; k < n; k++)
           cov[i][j] += data[i][k] * data[j][k];
           sum += data[i][k] * data[j][k];
         cov[i][j] /= (float_n - 1.0);
         cov[j][i] = cov[i][j];
       }
   */
}

   For the first loop I get the following debug info from clang and opt:
     LV: Checking a loop in "kernel_covariance" from test.c:10:7
     LV: Loop hints: force=? width=0 unroll=0
     LV: Found a loop: for.body3.us
     LV: PHI is not a poly recurrence.
     LV: PHI is not a poly recurrence.
     LV: Found an unidentified PHI.  %2 = phi i16 [ 0, %for.body.us ], [ %add.us, 
%for.body3.us ], !dbg !48
     LV: Can't vectorize the instructions or CFG
     LV: Not vectorizing: Cannot prove legality.

   Thank you,
     Alex


More information about the llvm-dev mailing list