-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
compiler_flags: Change optimization_fast from '-Ofast' to '-O3' #87495
base: main
Are you sure you want to change the base?
Conversation
There are other possibilities here, such as disable the warning for However, it seems like we want the meaning of this flag to be the same across all compilers, so I think it makes sense for whatever we do to be consistent. If we want to keep the unsafe optimizations, it might be good to rename it to something like |
@@ -21,7 +21,7 @@ endif() | |||
set_compiler_property(PROPERTY optimization_speed -O2) | |||
set_compiler_property(PROPERTY optimization_size -Os) | |||
set_compiler_property(PROPERTY optimization_size_aggressive -Oz) | |||
set_compiler_property(PROPERTY optimization_fast -Ofast) | |||
set_compiler_property(PROPERTY optimization_fast -O3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we choose to make this change, I'll add a context comment here so it doesn't accidentally get changed back in the future.
9919c29
to
a52b9d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR says changing for clang but is changing for gcc, clang changes should go in the clang file as per https://github.com/zephyrproject-rtos/zephyr/blob/a52b9d4084133edbdf547f308f5cb349a764fcc3/cmake/compiler/clang/compiler_flags.cmake#L1-L4]
GCC has no plans to deprecate this flag https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115990
'-Ofast' enables optimizations that are not standards compliant, which can produce unexpected results unless used carefully. When building with clang 19 and newer, it warns: clang: error: argument '-Ofast' is deprecated; use '-O3 -ffast-math' for the same behavior, or '-O3' to enable only conforming optimizations [-Werror,-Wdeprecated-ofast] Relevant discussion: * llvm/llvm-project#98736 * https://discourse.llvm.org/t/rfc-deprecate-ofast/78687/109 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115990 Signed-off-by: Tom Hughes <tomhughes@chromium.org>
a52b9d4
to
e42bd38
Compare
I think we want to be consistent on this on all compilers.
|
That's not possible, cause compilers has their own way / flags for handling this.
you forgot
I would say it's outside scope of Zephyr project to determine if the The main problems with appending
Developers should really understand what a given option does instead of just assuming.
I don't know the history for this flag, but changing it know will really impact things for everyone depending on current usage. Changing from |
If you're working on a safety critical system, that can indeed be unsafe. Perhaps a better name would be "non-compliant-math" or something to that effect.
It also enables
One possibility would be to abstract into two different settings. A "compliant/safe fast" and "non-compliant / unsafe fast". Each compiler could then define what that means (similar to how the other compiler settings are abstracted to allow each one to define an implementation that makes sense for it). |
I would still say that it depends on what you're using floats for, and if you remember to check for nan/inf, or error checks (if you don't do those checks, then fast-math or not doesn't really matter much as your code itself is unsafe). But I agree that in a safety critical system you would generally want to trade performance for extra checks, just to be on the extra safe side.
True, but this again depends on whether you have guarded your threads properly.
We could have a extra Lines 616 to 617 in 43e8f11
We could then have the Kconfig fast setting depend on such Note, i've used |
'-Ofast' enables optimizations that are not standards compliant, which can
produce unexpected results unless used carefully.
When building with clang 19 and newer, it warns:
clang: error: argument '-Ofast' is deprecated; use '-O3 -ffast-math' for
the same behavior, or '-O3' to enable only conforming optimizations
[-Werror,-Wdeprecated-ofast]
Relevant discussion:
-Ofast
driver option llvm/llvm-project#98736