I recently received a bug report about a program which fails to compile with the -O3 switch (see https://github.com/cschwan/sage-on-gentoo/issues/66). In particular, the problem is that compilation hangs at a certain point. The issue is solved by compiling with -O2 (I am well aware of the fact that programs compiled with -O3 may be broken, but I did not know that -O3 may hangup the compiler). If you want to reproduce the issue run
wget http://perso.ens-lyon.fr/xavier.pujol/fplll/libfplll-3.0.12.tar.gz
tar -xf libfplll-3.0.12.tar.gz
cd libfplll-3.0.12
./configure CXXFLAGS="-O3"
make
I wondered why -O3 hangs up the compiler and so I tried to track down the issue. First, I tried to find out the the difference between -O2 between -O3. Gcc's man page states that -O3 enables the switches of -O2 and the following ones (lets call them x
):
-finline-functions -funswitch-loops -fpredictive-commoning -fgcse-after-reload
-ftree-vectorize -fipa-cp-clone
I verified that by comparing the output of gcc when invoked with -Q -O2 --help=optimizers
and -Q -O3 --help=optimizers
. I then planned to selectively remove the switches in order to find the one which causes the problem. However, compilation works fine with -O2 and the additional switches above, so I conclude
-O3 != -O2 x
Now my question: Does anybody know if there is a further difference between -O2 and -O3 (undocumented?), has anyone experienced a similar behavior ? Is this maybe a compiler bug ?