Monday, March 28, 2022

[SOLVED] Is `-ftree-slp-vectorize` not enabled by `-O2` in GCC?

Issue

From https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

It says "-ftree-slp-vectorize: Perform basic block vectorization on trees. This flag is enabled by default at -O2 and by -ftree-vectorize, -fprofile-use, and -fauto-profile."

However it seems I have to pass a flag explicitly to turn on SIMD. Did I mis undertand something here? It is enabled at -O3 though.

https://www.godbolt.org/z/1ffzdqMoT


Solution

Is -ftree-slp-vectorize not enabled by -O2 in GCC?

Yes and no. It depends on the version of the compiler.

From https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

You have linked to the latest version of documentation. It applies to the version that is currently under development, which at the moment is version 12.

However it seems I have to pass a flag explicitly to turn on SIMD.

https://www.godbolt.org/z/1ffzdqMoT

Your example uses GCC version 11.

Did I mis undertand something here?

You read the wrong version of documentation, or used wrong version of compiler and hence your assumption didn't hold.



Answered By - eerorika
Answer Checked By - David Goodson (WPSolving Volunteer)