gcc -O4 optimization flag - c++

What's the meaning of the -O4 optimization flag in gcc (3.2.3)? What's the difference to O3? When would you use one vs. the other?
The man pages only mention O, O0-3, Os, no word of the mysterious O4. Thanks!

There is no -O4 in 3.2.3.
Everything above -O3 results in -O3 being chosen.

You can check what optimization are enabled for each level
gcc -c -Q -O3 --help=optimizers | grep enabled
It works at least for gcc 4.4.

Related

Possibility to use GCC "--enable-frame-pointer" for 64bit targets

I'd like to ensure that a large set projects are build with the -fno-omit-frame-pointer flag for easier debugging with tools like ebpf.
One way of course would be to modify the build scripts of each of these projects, but that is a lot of work.
I've come across the possibility to configure gcc with --enable-frame-pointer which restores the old default from the early gcc4.x days of using -fno-omit-frame-pointer.
I've built gcc from source like that and confirmed:
❯ ./bin/gcc -m32 -O3 -Q --help=optimizers | grep omit
-fomit-frame-pointer [disabled]
❯ ./bin/gcc -m64 -O3 -Q --help=optimizers | grep omit
-fomit-frame-pointer [enabled]
Is anyone aware of a possibility to extend the effect of --enable-frame-pointer to the 64bit targets?
I believe you are using an older version of GCC because support of this flag on x64 has been enabled some time ago (see e.g. this commit).

g++: Will -fno-omit-frame-pointer be effective if specified before -O2 or -O3?

We have a complex hierarchical make file system where the CXXFLAGS is appended in several places (several separate makefiles of individual libraries).
There's one master file that seems to be getting included in every other make file. So I specified the -fno-omit-frame-pointer flag there.
When I compile, I see the above flag and after that I see -O2. My question is, if the -O2 flag sets -fomit-frame-pointer, will the latest setting take effect?
With gcc/g++ you can use the -Q --help=optimizers flags to find out the exact set of optimizations that are enabled.
With my version of gcc I get:
$ gcc -Q --help=optimizers -O2 | fgrep omit-frame-pointer
-fomit-frame-pointer [enabled]
and
$ gcc -Q --help=optimizers -fno-omit-frame-pointer -O2 | fgrep omit-frame-pointer
-fomit-frame-pointer [disabled]
So -O2 doesn't seem to overwrite the previous -fno-omit-frame-pointer.
Anyway check your environment.

Is it possible to get vectorisation report with g++ or clang++ - openmp

I want to get the vectorisation report regrading automated vectorisation and openmp SIMD.
# gcc
-fopenmp-simd -O3 -ffast-math -march=native -fopt-info-omp-vec-optimized-missed
# clang
-fopenmp-simd -O3 -ffast-math -march=native -Rpass="loop|vect" -Rpass-missed="loop|vect" -Rpass-analysis="loop|vect"
# icc on Linux
-qopenmp-simd -O3 -ffast-math -march=native -qopt-report-file=stdout -qopt-report-format=vs -qopt-report=5 -qopt-report-phase=loop,vec
# msvc
-openmp -O2 -fp:fast -arch:AVX2 -Qvec-report:2
I don't think Apple's flavor of clang supports OpenMP (At least not by default on macOS).
You may find ways to extend it though.

Vectorization with gcc5 gives no information

I was trying some vectorisation after upgrading g++ from version 4.8.5 to 5.4.1. With this flags:
g++ particles-v3.cpp -o v3 -O3 -msse4.2 -mfpmath=sse -ftree-vectorizer-verbose=5 -ffast-math -m32 -march=native -std=c++11
While the same command gives over 4000 lines of detailed information about the vectorization with g++-4.8, with g++-5.4 it does not say anything.
Is there some major change in g++-5 that makes the -ftree-vectorizer-verbose=X unusable, or is there simply somethin wrong in the line? How to change it so that it works?
EDIT:
found out that using -fopt-info-vec-all gives exacty the info I wanted. Thus question solved.

Does gcc 4.8.1 enable sse by default?

I experienced crashes running an old code of mine on a system which doesn't support SSE4.1, I debugged a bit and found SSE instructions in the glibc, is that possible? Why isn't this reported in gcc 4.8.1 release notes?
You can see what optimizations are used by GCC with the following command:
$ gcc -Q --help=target
For instance, on my machine, GCC does not enable sse4.1 by default:
$ gcc -Q --help=target | grep msse4.1
-msse4.1 [disabled]
However, it is supported because it appears in /proc/cpuinfo. And indeed, if I ask GCC to optimize the generated code for my machine, it enables sse4.1:
$ gcc -Q --help=target -march=native | grep msse4.1
-msse4.1 [enabled]