[cfe-dev] clang auto-vectorization feedback is confusing

Sean McBride via cfe-dev cfe-dev at lists.llvm.org
Thu Jun 30 09:12:43 PDT 2016


Hi all,

I'm experimenting with clang's ability to auto-vectorize loops and am having trouble knowing when it succeeds or not.

Consider a stupid example reduced from real code:

--------test.c-------
#include <stdio.h>

int foo(int *A, int *B, int n) {

#pragma clang loop vectorize(enable)
	for (int k = 0; k < n; ++k)
	{
	  unsigned sum = 0;

#pragma clang loop vectorize(enable)
	  for (int i = 0; i < n; ++i)
		   sum += A[i] + 5;

	  printf("%i", sum);
	}

 return 0;
}
---------------

$ clang -S -fvectorize -O3 -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize ~/Desktop/test.c
/Users/sean/Desktop/test.c:11:4: remark: vectorized loop (vectorization width: 4, interleaved count: 2) [-Rpass=loop-vectorize]
          for (int i = 0; i < n; ++i)
          ^

It helpfully says it vectorized the inner loop, but says *nothing* about the outer loop.  If I comment out the printf(), then it outputs nothing whatsoever.  Is this because earlier optimizer passes are basically destroying/transforming away the loop before the vectorizer sees it?

I'm trying to rework some code to be vectorizable, and various tweaks are causing clang to become silent or noisy.  Any suggestions on how I can reliably know if a loop will be vectorized, or reliably know the loop was transformed to something else?

Thanks,

Sean





More information about the cfe-dev mailing list