Skip to content

Start using optimization (-O0/-O2/-O3/-Os) and debug (-g) flags from CMAKE_CXX_FLAGS_${CFLAGS_BUILD_TYPE} #33388

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

Merged
merged 7 commits into from
Aug 18, 2020

Conversation

kubamracek
Copy link
Contributor

No description provided.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

This is definitely a pretty big improvement.

@kubamracek
Copy link
Contributor Author

I want to point out that this changes one of the optimization levels. The CMake defaults are:

CMAKE_CXX_FLAGS_DEBUG = -g
CMAKE_CXX_FLAGS_MINSIZEREL = -Os -DNDEBUG
CMAKE_CXX_FLAGS_RELEASE = -O3 -DNDEBUG
CMAKE_CXX_FLAGS_RELWITHDEBINFO = -O2 -g -DNDEBUG

While currently Swift forces -O2 on Release. So this will be a change to -O3 here.

@kubamracek kubamracek force-pushed the flags_from_build_type branch from d515898 to 7ccbc75 Compare August 12, 2020 16:12
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - cb5de39c4715e9b74efed0486f80ca68b1026a41

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - cb5de39c4715e9b74efed0486f80ca68b1026a41

@kubamracek
Copy link
Contributor Author

@swift-ci please test macOS platform

1 similar comment
@kubamracek
Copy link
Contributor Author

@swift-ci please test macOS platform

@kubamracek
Copy link
Contributor Author

@gottesmm @airspeedswift @aschwaighofer Any more feedback here? Any concerns about the switch to -O3 for Release (not for RelWithDebInfo though)?

@airspeedswift
Copy link
Member

We really need to do a benchmark run and see the impact on that.

@aschwaighofer
Copy link
Contributor

aschwaighofer commented Aug 13, 2020

Isn't -O3 clang's benchmarking mode? By that I mean the kitchen sink that is used when compiling 'insert your favorite commercial benchmark here' . And -Os/-O2 is meant to be more sane.

What are the code size impacts of using -O3 over -Os on the c++ part of the standard library?

I seemed to remember the loop vectorizer for example inserts speculative code aggressively in the highest opt mode.

@kubamracek
Copy link
Contributor Author

Okay, so it sounds like there are concerns. @compnerd how about I do something like:

set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")

to turn this PR into a NFC, and we can discuss separately whether we should switch to the CMake's default?

@kubamracek
Copy link
Contributor Author

Ok, this is now a NFC change only.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test Windows platform

1 similar comment
@kubamracek
Copy link
Contributor Author

@swift-ci please test Windows platform

@kubamracek
Copy link
Contributor Author

Hm, the Windows bot failure looks like a real regression: https://ci-external.swift.org/job/swift-PR-windows/6268/console. @compnerd any ideas what's causing it?

@kubamracek
Copy link
Contributor Author

@swift-ci please test Windows platform

@kubamracek
Copy link
Contributor Author

@swift-ci please test Windows platform

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - cd2c471

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - cd2c471

CMakeLists.txt Outdated
@@ -629,6 +629,19 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQU
set(SWIFT_COMPILER_IS_MSVC_LIKE TRUE)
endif()

if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
# Avoid CMake's default -O3 for Release builds.
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
Copy link
Member

Choose a reason for hiding this comment

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

Please don't set -DNDEBUG, that overrides the behaviour of LLVM_ENABLE_ASSERTIONS. I usually build with assertions intentionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the default in CMAKE_CXX_FLAGS_RELEASE, though. I though it would be better to keep it that way, because we're explicitly checking LLVM_ENABLE_ASSERTIONS and passing -UNDEBUG or -DNDEBUG after we include CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 5066bea

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 5066bea

@kubamracek kubamracek merged commit 28a2826 into swiftlang:master Aug 18, 2020
@kubamracek kubamracek deleted the flags_from_build_type branch August 18, 2020 02:26
@gottesmm
Copy link
Contributor

@kubamracek leaving swift at -O2 is the correct thing to do here! Thanks for keeping it like that!

edymtt added a commit to edymtt/swift that referenced this pull request Sep 1, 2020
Set those at the value pre swiftlang#33388 -- this would avoid regressions
of disk space usage (in particular around building Swift LTO)

Addresses rdar://68091272
edymtt added a commit that referenced this pull request Sep 1, 2020
Set those at the value pre #33388 -- this would avoid regressions
of disk space usage (in particular around building Swift LTO)

Addresses rdar://68091272
kubamracek added a commit to kubamracek/swift that referenced this pull request Sep 12, 2020
…gs from CMAKE_CXX_FLAGS_${CFLAGS_BUILD_TYPE} (swiftlang#33388)"

This reverts commit 28a2826.
kubamracek added a commit that referenced this pull request Sep 12, 2020
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.

6 participants