Does clang compile kernel yet? If not it can lick GCC boots.
Announcement
Collapse
No announcement yet.
LLVM Clang 16 vs. GCC 13 Compiler Performance On Intel Raptor Lake
Collapse
X
-
Originally posted by ryao View Post
​
Different compilers make different choices for what optimization levels mean. If GCC’s developers do not want to enable optimizations as part of them, then it is fair to let benchmarks reflect that.
-fsemantic-interposition is similar in nature to -ffast-math and other options we have to be more lenient about standards.
Just because some compiler do equivalent of -ffast-math as part of -O3 does not mean that GCC should do it.
Just like -ffast-math, -fsemantic-interposition is now enabled by -Ofast.
Semantic interposition is an useful feature, but I would personally not be offended if was opt-in rather then opt-out, since shared libraries are much more complex then what ELF was originally designed for. See discussion at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100937
Sime distros compile with -fno-semantic-interposition by default.
For benchmarking the quality of compiler optimizations it is however quite important to be sure that all compilers considered adhere to similar set of rules. Sadly we tend to diverge between clang and GCC in what individual optimization settings really means.
- Likes 5
Comment
-
Originally posted by hubicka View Post
-fno-semantic-interposition is not an optimization. It is flag telling compiler to ignore ELF interposition rules. Doing so enables other optimizations (such as inlining, constant propagation etc.). GCC at -O3 optimization levels should be standard conforming (with few well justified exceptions), so enabling semantic interposition would need agreement outside of GCC community on updating ELF standard.
(in an ideal world, the information how the symbol is to be used comes from the linker and not marks in the source-code, requiring at least some mild form of LTO or turning the build-process upside-down)Last edited by discordian; 12 May 2023, 07:49 AM.
- Likes 1
Comment
-
Originally posted by discordian View Post
The example you provided contained a function that is not marked to be exported, so ELF interposition is not an argument. Which functions are eligible to be exported is not standardized, the sane thing to do would add a macro notifying that. gcc leaves valid optimizations on the table, unless your example is missing some crucial details.
(in an ideal world, the information how the symbol is to be used comes from the linker and not marks in the source-code, requiring at least some mild form of LTO or turning the build-process upside-down)
If you compile the testcase with -fvisibility=hidden, GCC will optimize return to 1. GCC has quite careful logic about what can be interposed:- Interposition is possible only with -fpic or weak symbols
- Inline functions or comdats can not be be semantically interposed (but can be interposed to different, equivalent definition possibly optimized with different optimization flags or compiled by other compiler)
- With -flto, one can use resolution file to hide symbols at link-time (as you suggest) and GCC will be informed about this (it will see that the symbol is not LDPR_PREVAILING_DEF_IRONLY and optimize accordingly)
- If you compile with -fpic but link resulting object into non-shared binary, GCC will know this from linker plugin too and disable inteprosition.
Problem is that Clang exports the symbol in my testcase yet does not expect the interposition to happen. This is not considered to be a good idea in GCC (as discussed few times at the mailing-list).
- Likes 2
Comment
-
Originally posted by hubicka View Post
Both GCC and Clang require -fvisibility=hidden to not export the symbol. Making -fvisibility=hidden a default would break a lot of existing packages that does not mark exported symbols.
Originally posted by hubicka View PostIf you compile the testcase with -fvisibility=hidden, GCC will optimize return to 1. GCC has quite careful logic about what can be interposed:- Interposition is possible only with -fpic or weak symbols
- And that comes with a cost: inefficent code and relocations.
Originally posted by hubicka View Post- Inline functions or comdats can not be be semantically interposed (but can be interposed to different, equivalent definition possibly optimized with different optimization flags or compiled by other compiler)
- With -flto, one can use resolution file to hide symbols at link-time (as you suggest) and GCC will be informed about this (it will see that the symbol is not LDPR_PREVAILING_DEF_IRONLY and optimize accordingly)
Originally posted by hubicka View Post- If you compile with -fpic but link resulting object into non-shared binary, GCC will know this from linker plugin too and disable inteprosition.
Originally posted by hubicka View PostProblem is that Clang exports the symbol in my testcase yet does not expect the interposition to happen. This is not considered to be a good idea in GCC (as discussed few times at the mailing-list).
Comment
- Interposition is possible only with -fpic or weak symbols
Comment