Why vectorization didn't turn on by -O2

Richard Biener rguenther@suse.de
Mon May 10 08:21:04 GMT 2021


On Sun, 9 May 2021, Segher Boessenkool wrote:

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

In particular -O2 is a balance of compile-time, generated code size
and resulting performance.  Vectorization with the -O2 default
cost model of "cheap" tends to mostly increase the first and the second
whilst only moderately affecting the last.

It's all of course hugely dependent on the source base you are
working with.

Richard.

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