How can I disable vectorization while using GCC?

you can also selectively enable and disable vectorization with the optimize function attributes or pragmas

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

http://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html

e.g.

__attribute__((optimize("no-tree-vectorize")))
void f(double * restrict a, double * restrict b)
{
    for (int i = 0; i < 256; i++)
        a[i] += b[i];
}

Most of the GCC switches can be used with a no prefix to disable their behavior. Try with -fno-tree-vectorize (after -O3 on the command line).


Excellent, now that gcc has become more aggressive at vectorizing e.g.

extern "C" __attribute__((optimize("no-tree-vectorize")))
/* Subroutine */
int s111_ (integer * ntimes, integer * ld, integer * n,
           real * ctime, real * dtime,
           real * __restrict a, real * b, real * c__, real * d__,
           real * e, real * aa, real * bb, real * cc)
{
    ....
    for (i__ = 2; i__ <= i__2; i__ += 2)
        a[i__] = a[i__ - 1] + b[i__];
    ....

In the case posted above, removing restrict used to do the job, but now g++ 6.0 can't be stopped from vectorizing by removing __restrict.