我有以下C程序(这是我的实际用例的简化版本,展示了相同的行为)
#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
内部for循环的行数为10。当我查找原因时,结果显示指针可能存在别名(alias),但在我的代码中它们没有别名,因为我使用了__restrict关键字。他们还建议包括-msse标志,但它们似乎也没有起作用。需要帮助吗?