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

Adam Nemet via cfe-dev cfe-dev at lists.llvm.org
Thu Jun 30 09:53:41 PDT 2016


> On Jun 30, 2016, at 9:12 AM, Sean McBride via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> 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.

Currently the vectorizer does not visit outer loops and the diagnostics is emitted in the vectorizer so we don’t get a chance to report anything.  Can you please file a bug?

>  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?

Sort of, it’s because the loops are removed.  I am not sure what the expected behavior should be in this case...

> 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?

I am not sure there is anything beyond what you’re doing right now.  You could look at the internal debug dumps with a debug version of clang but probably the best thing to do is to file PRs on anything that does not make sense to you.

Thanks for reporting.

Adam

> 
> Thanks,
> 
> Sean
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list