Why vectorization didn't turn on by -O2

Segher Boessenkool segher@kernel.crashing.org
Sun May 9 13:44:37 GMT 2021


On Sun, May 09, 2021 at 12:54:08AM +0800, Xi Ruoyao via Gcc-help wrote:
> On Sat, 2021-05-08 at 20:07 +0800, 172060045@hdu.edu.cn wrote:
> > Recently I noticed that gcc -O2 didn't turn on vectorization
> > optimization, 
> > which it turns on in clang -O2.
> > 
> > Does GCC think it involves the trade-off of space speed, or other
> > considerations?

-O2 is for optimisations that (almost) never degrade code quality.  -O3
is for those that are only beneficial "on average".

> It's just a decision I think.  The "original" reason may be that
> vectorization can make code *slower* on some cases.

Yup.  Vectorisation always causes hugely different code.

> There was some discussion about enabling -ftree-loop-vectorization at -
> O2 for x86, but that was too late (for GCC 9):

AFAIK the current plan is to enable vectorisation at -O2 with a more
conservative cost model.  This will be a generic change, for all
architectures, and hopefully will arrive in GCC 12.


Segher


More information about the Gcc-help mailing list