I, too, had a disappointing experience looking for answers.
Specifically: The following helped for me (up-to-date Ubuntu May 2013). Try both -fno-reorder-functions
and -fno-inline
. For example, under cmake, this worked:
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(${CMAKE_CXX_FLAGS} "-Ofast")
add_definitions(${CMAKE_CXX_FLAGS} "-fno-reorder-functions")
add_definitions(${CMAKE_CXX_FLAGS} "-fno-inline")
endif()
Generally: Try looking at the compiler optimization docs. Find an optimization level that works, and then add all the listed options for the next level. Try adding and removing with, say, bisection. Again, in cmake something like:
add_definitions(${CMAKE_CXX_FLAGS} "-O1")
add_definitions(${CMAKE_CXX_FLAGS} "-fthread-jumps")
add_definitions(${CMAKE_CXX_FLAGS} "-falign-functions -falign-jumps")
add_definitions(${CMAKE_CXX_FLAGS} "-falign-loops -falign-labels")
# add_definitions(${CMAKE_CXX_FLAGS} "-fcaller-saves")
# add_definitions(${CMAKE_CXX_FLAGS} "-fcrossjumping")
# add_definitions(${CMAKE_CXX_FLAGS} "-fcse-follow-jumps -fcse-skip-blocks")
# add_definitions(${CMAKE_CXX_FLAGS} "-fdelete-null-pointer-checks")
It may well be that one or two optimization options are causing all the problems.