3

I want to turn off auto-vectorization for specific loops in a function. How can I do this with GCC? I know I can turn auto-vectorization off for the whole function with __attribute__((optimize("no-tree-vectorize"))) but how do I do this for individual loops in a function (with MSVC I can use add #pragma loop(no_vector)).

void dot_int(int * __restrict a, int * __restrict b, int * __restrict c) { 
    for(int i=0; i<1024; i++) {        
        c[i] = a[i] + b[i];
    }
    //#pragma loop(no_vector)  //don't vectorize this loop
    for(int i=0; i<1024; i++) {        
        c[i] = a[i] + b[i];
    }
}
Z boson
  • 32,619
  • 11
  • 123
  • 226
  • May I ask why you want to do that? – Biffen May 16 '14 at 15:27
  • I'm trying to separate the vectorized loop into the vectorized and non-vectorzied part. The way it is now I can only get one. I tried using separate inline functions but that did not work. – Z boson May 19 '14 at 07:25

1 Answers1

0

In case anyone cares I came up with a solution. It's really the inverse. Rather than disabling auto-vectorization for certain loops it only enables it for certain loops.

To do this compile with -O2 and use #pragma omp simd like this.

void dot_int(int * __restrict a, int * __restrict b, int * __restrict c) {
    #pragma omp simd 
    for(int i=0; i<1024; i++) {        
        c[i] = a[i] + b[i];
    }

    for(int i=0; i<1024; i++) {        
        c[i] = a[i] + b[i];
    }
}

Thought the vectorization of #pragma omp simd does not necessarily generate the same code as vectorization with -O3.

Z boson
  • 32,619
  • 11
  • 123
  • 226