为什么循环在一定数量的元素后不向量化?

问题描述

我制作了一个矩阵向量乘法函数,它可以很好地自动向量化,当数组小于 16x16 大小时,使用 GCC 11.2 编译会生成向量化代码:

 #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];
    }
    }
}

但是,当我将元素数量增加到 24、32 等时,编译器会给出以下警告:


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

而且代码没有向量化。

有什么可以做的吗?

解决方法

正如 tstanisl 评论的那样,添加限制关键字解决了这个问题。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...