GCC: vectorization difference between two similar loops

前端 未结 4 2123
误落风尘
误落风尘 2020-12-24 06:18

When compiling with gcc -O3, why does the following loop not vectorize (automatically):

#define SIZE (65536)

int a[SIZE], b[SIZE], c[SIZE];

in         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 06:34

    The first loop is equivalent to

    #define SIZE (65536)
    
    int a[SIZE], b[SIZE], c[SIZE];
    
    int foo () {
      int i, j;
    
      for (i=0; i c[SIZE - 1] ? b[i] : c[SIZE - 1];
      }
      return a[0];
    }
    

    The problem with the original expression is that it really doesn't make that much sense, so it's not too surprising gcc isn't able to vectorize it.

提交回复
热议问题