我有以下的C程序(我的实际使用情况的简化表现出相同的行为)GCC为什么不自动矢量化这个循环?
#include <stdlib.h>
#include <math.h>
int main(int argc, char ** argv) {
const float * __restrict__ const input = malloc(20000*sizeof(float));
float * __restrict__ const output = malloc(20000*sizeof(float));
unsigned int pos=0;
while(1) {
unsigned int rest=100;
for(unsigned int i=pos;i<pos+rest; i++) {
output[i] = input[i] * 0.1;
}
pos+=rest;
if(pos>10000) {
break;
}
}
}
当我与
-O3 -g -Wall -ftree-vectorizer-verbose=5 -msse -msse2 -msse3 -march=native -mtune=native --std=c99 -fPIC -ffast-math
编译我得到的输出
main.c:10: note: not vectorized: unhandled data-ref
其中10是内循环的行。当我查询它为什么会这样说时,它似乎是说指针可能是别名,但它们不能在我的代码中,因为我有__restrict关键字。他们还建议包括-msse标志,但他们似乎也没有做任何事情。任何帮助?
什么版本的gcc?一个可行的例子也可能是有用的,因为当我尝试使用4.4.5 – ergosys 2011-02-16 23:15:16
进行向量化时,你可以发布编译的代码示例吗?当我填充了一些虚拟值时,循环被矢量化了...... – Christoph 2011-02-16 23:15:39
@ergosys:他说的;) – Christoph 2011-02-16 23:16:00