I have made a matrix-vector multiplication function which is nicely auto-vectorized, when array is under 16x16 size, compiling with GCC 11.2 results in vectorized code:
#define no_el 16
void mv_mul(float arr[no_el][no_el],float a1[no_el],float a2[no_el])
{
for(int i=0;i<no_el;i++)
{
a2[i]=0;
for(int j=0;j<no_el;j++)
{
a2[i]+=arr[i][j]*a1[j];
}
}
}
However, when I increase number of elements to 24, 32, etc. the compiler gives these warnings:
Output of x86-64 gcc 11.2 (Compiler #1)
<source>:7:18: missed: couldn't vectorize loop
<source>:12:11: missed: not vectorized: complicated access pattern.
<source>:10:18: missed: couldn't vectorize loop
<source>:12:11: missed: not vectorized: complicated access pattern.
<source>:5:7: note: vectorized 0 loops in function.
<source>:15:1: note: ***** Analysis failed with vector mode V8SF
<source>:15:1: note: ***** Skipping vector mode V32QI, which would repeat the analysis for V8SF
And the code is not vectorized.
Is there anything that can be done ?
As tstanisl commented, adding restrict keyword solved the issue.