Skip to content

cmake: use -flto=auto compiler flag when supported, rework fast-math disablement #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

illwieckz
Copy link
Member

@illwieckz illwieckz commented Mar 5, 2025

cmake: use -flto=auto compiler flag when supported

Use -flto=auto compiler flag when supported, this silence this
GCC warning:

lto-wrapper: warning: using serial compilation of # LTRANS jobs

This also greatly speeds-up the linkage time as it enables LTO
multithreading in GCC (either by using Make jobserver if detected,
either by detecting CPU cores).

Also always set LTO if enabled.

Similar to:

cmake: rework the fast-math enablement and force the disablement

Some compilers may enable fast-math by default (example: ICC).
Some contractions are still safe and can be enabled.

cmake: fix typo

Use -flto=auto compiler flag when supported, this silence this
GCC warning:

> lto-wrapper: warning: using serial compilation of # LTRANS jobs

This also greatly speeds-up the linkage time as it enables LTO
multithreading in GCC (either by using Make jobserver if detected,
either by detecting CPU cores).

Also always set LTO if enabled.
Some compilers may enable fast-math by default (example: ICC).
Some contractions are still safe and can be enabled.
@illwieckz illwieckz changed the title Illwieckz/cmake cmake: use -flto=auto compiler flag when supported Mar 17, 2025
@illwieckz illwieckz changed the title cmake: use -flto=auto compiler flag when supported cmake: use -flto=auto compiler flag when supported, rework fast-math disablement Mar 17, 2025
@illwieckz illwieckz force-pushed the illwieckz/cmake branch 3 times, most recently from 2abc19b to 27c13ac Compare March 17, 2025 17:45
Copy link
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any numbers on performance impact of the strict math flags? Reproducible floating-point operations are of somewhat niche interest and have limited chance to be reliably achieved between differing compilers and architectures, so I think that would be a bad default if it costs more than a few percent of speed.

@@ -88,12 +98,8 @@ if (MSVC)
endif()

if (USE_LTO)
set_cxx_flag("/GL" RELEASE)
set_cxx_flag("/GL" RELWITHDEBINFO)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of these is to have different flags per configuration in a multi-configuration build, so that you can test a Release build with LTO and a Debug build without it from the same IDE instance.

It's OK to remove this for the GCC-style options since it gets in the way of flag tests, but there is no need to remove it for MSVC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants