I am trying to selectively unroll the second loop in the following program:
#include <stdio.h>
int main()
{
int in[1000], out[1000];
int i,j;
#pragma nounroll
for (i = 100; i < 1000; i++)
{
in[i]+= 10;
}
#pragma unroll 2
for (j = 100; j < 1000; j++)
{
out[j]+= 10;
}
return 1;
}
When I run clang (3.5) with the following options, it unrolls both the loops 4 times.
clang -std=c++11 -O3 -fno-slp-vectorize -fno-vectorize -mllvm -unroll-count=4 -mllvm -debug-pass=Arguments -emit-llvm -c *.cpp
What am I doing wrong? Also, if I add -fno-unroll-loops
, or skip the -unroll-count=4
flag, it does not unroll any loop.
Also, any hints on how to debug pragma errors?
-unroll-count=4
has a higher priority than#pragma clang loop unroll_count(2)
. That's why it ends up unroll it by 4. Meaning the compiler is following the unroll-count command line option NOT the pragma. Also as plasmacel mentioned, #pragma clang loop unroll is not supported before clang 3.6.