Translations:GCC optimization/111/en
-ftree-vectorize
is an optimization option (default at -O2
and up), which attempts to vectorize loops using the selected ISA if possible. The reason it previously wasn't enabled at -O2
is that it doesn't always improve code, it can make code slower as well, and usually makes the code larger; it really depends on the loop etc. As of GCC 12, it is enabled by default at -O2
with a low cost model (-fvect-cost-model=very-cheap
) to strike a balance between code size and speed benefits. The cost model can be specified with -fvect-cost-model
. Alternative vectorization cost models include: cheap
, dynamic
, and unlimited
. The dynamic
cost model (default at -O3
) is going to estimate the cost of the loop using scalar instructions and vector instructions and will be able to decide whether vectorization is profitable using either compile time or runtime checks. The cheap
cost model is similar to dynamic
, although slighty more conservative, it will not take effect if the runtime checks for data dependencies or alignment exceed the parameters. The unlimited
cost model assumes that vectorization is always profitable, making it switch from auto-vectorization to explicit vectorization, but it should never be used system-wide as it will cause severe code bloat.