Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tree vectorization: gcc optimization flag

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?

like image 735
DevShark Avatar asked Mar 10 '16 12:03

DevShark


People also ask

How do I enable vectorization in GCC?

Modern versions of GCC enable -ftree-vectorize at -O3 so just use that in GCC4.x and later: (Clang enables auto-vectorization at -O2. ICC defaults to optimization enabled + fast-math.) Most of the following was written by Peter Cordes, who could have just written a new answer. Over time, as compilers change, options and compiler output will change.

What is the GCC ICF optimization flag?

Although the behavior is similar to the Gold Linker’s ICF optimization, GCC ICF works on different levels and thus the optimizations are not same - there are equivalences that are found only by GCC and equivalences found only by Gold. This flag is enabled by default at -O2 and -Os .

How do I enable vectorization on a tree in Linux?

Perform basic block vectorization on trees. This flag is enabled by default at -O3 and by -ftree-vectorize, -fprofile-use , and -fauto-profile . Initialize automatic variables with either a pattern or with zeroes to increase the security and predictability of a program by preventing uninitialized memory disclosure and use.

What happens when you turn on optimization flags in C++?

Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program. The compiler performs optimization based on the knowledge it has of the program.


1 Answers

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.

like image 158
MSalters Avatar answered Oct 27 '22 00:10

MSalters