3
votes

I have noticed that the gcc flag -ftree-vectorize is very useful for optimizing code.

I am trying to understand better how it works, but the doc is fairly concise:

Perform vectorization on trees. This flag enables -ftree-loop-vectorize and -ftree-slp-vectorize if not explicitly specified.

Does anyone know the inner workings of this flag?

1
This link might be of some use: Vectorization in gcc - mindriot
As noted in the linked document, additional insight into the inner workings of the optimizer can be obtained by playing with the -ftree-vectorizer-verbose=N option. - nucleon
"SLP" is Superword Level Parallelism. Not all repeated instructions are due to loop unrolling; some are because the underlying code is naturally repetitive. - MSalters
I suggest reading my paper about SIMD - Martin

1 Answers

6
votes

Trees are an internal code representation used by GCC, and tree vectorization happens in this stage. In this representation, it's fairly easy to spot repeated instructions. If the code generator can emit SIMD instructions, it helps to bundle these repeated instructions already in the tree stage.

See tree-vectorizer.c for details.