How can I disable vectorization while using GCC?

孤者浪人 提交于 2019-12-21 11:35:21

问题


I am compiling my code using following command:

gcc -O3 -ftree-vectorizer-verbose=6 -msse4.1 -ffast-math 

With this all the optimizations are enabled.

But I want to disable vectorization while keeping the other optimizations.


回答1:


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).




回答2:


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];
}



回答3:


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.



来源:https://stackoverflow.com/questions/7778174/how-can-i-disable-vectorization-while-using-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!