From cdc2b1b5b5e79c667ebb3989f622621f7e829122 Mon Sep 17 00:00:00 2001 From: vng Date: Sat, 4 Sep 2021 23:51:50 +0200 Subject: [PATCH] Added LTO and -Ofast. Signed-off-by: Viktor Govako --- CMakeLists.txt | 24 +++++++++++++++++++++++- geometry/geometry_tests/robust_test.cpp | 10 +++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b48a77176..994b486e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,11 @@ if (PLATFORM_WIN) ) endif() +# Try fast native arch. +if (PLATFORM_LINUX) + add_compile_options(-march=native) +endif() + # Built-in CMake configurations: Debug, Release, RelWithDebInfo, MinSizeRel if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") add_definitions(-DDEBUG) @@ -103,12 +108,29 @@ if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") elseif (${CMAKE_BUILD_TYPE} MATCHES "Rel") add_definitions(-DRELEASE) if (NOT MSVC) - add_compile_options(-Ofast) # Also enables -ffast-math + add_compile_options(-Ofast $<$:-flto=auto>) # Also enables -ffast-math endif() else() message(FATAL_ERROR "Unknown build type: " ${CMAKE_BUILD_TYPE}) endif() +if (${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") + add_compile_options(-fno-omit-frame-pointer) +endif() + +# Linux GCC LTO plugin fix. +if (PLATFORM_LINUX AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_BUILD_TYPE MATCHES "^Rel")) + # To force errors if LTO was not enabled. + add_compile_options(-fno-fat-lto-objects) + # To fix ar and ranlib "plugin needed to handle lto object". + string(REGEX MATCH "[0-9]+" GCC_MAJOR_VERSION ${CMAKE_CXX_COMPILER_VERSION}) + file(GLOB_RECURSE plugin /usr/lib/gcc/*/${GCC_MAJOR_VERSION}/liblto_plugin.so) + set(CMAKE_C_ARCHIVE_CREATE " --plugin ${plugin} qcs ") + set(CMAKE_C_ARCHIVE_FINISH " --plugin ${plugin} ") + set(CMAKE_CXX_ARCHIVE_CREATE " --plugin ${plugin} qcs ") + set(CMAKE_CXX_ARCHIVE_FINISH " --plugin ${plugin} ") +endif() + message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) if (PLATFORM_LINUX OR PLATFORM_ANDROID) diff --git a/geometry/geometry_tests/robust_test.cpp b/geometry/geometry_tests/robust_test.cpp index aaf1db368..b876ba74a 100644 --- a/geometry/geometry_tests/robust_test.cpp +++ b/geometry/geometry_tests/robust_test.cpp @@ -62,8 +62,12 @@ UNIT_TEST(Segment_Smoke) TEST(!OnSegment(P(10 + eps, 10), ps), ()); TEST(!OnSegment(P(0, 0), ps), ()); } +} - // Paranoid tests. +// This paranoid test doesn' work with Release optimizations (LTO?). +#ifndef NDEBUG +UNIT_TEST(Segment_Paranoid) +{ { P ps[] = {{0, 0}, {1e100, 1e100}}; TEST(OnSegment(ps[0], ps), ()); @@ -94,6 +98,7 @@ UNIT_TEST(Segment_Smoke) TEST(!OnSegment(P(1e-16, 2.0 * 1e-16), ps), ()); } } +#endif UNIT_TEST(Triangle_Smoke) { @@ -129,6 +134,8 @@ UNIT_TEST(Triangle_PointInsideSegment) TEST(!InsideTriangle(P(eps, eps), ps), ()); } +// This paranoid test doesn' work with Release optimizations (LTO?). +#ifndef NDEBUG UNIT_TEST(Triangle_PointInsidePoint) { double constexpr eps = 1.0E-10; @@ -147,6 +154,7 @@ UNIT_TEST(Triangle_PointInsidePoint) TEST(!InsideTriangle(P(eps, eps), ps), ()); #endif } +#endif UNIT_TEST(PolygonSelfIntersections_IntersectSmoke) {