2 ms·
I'm once again surprised at GCC being slower than clang. I would have thought that GCC, which had a 20? year head start would've made faster code. And yet, occa
by Neywiny 10mo ago
I'm once again surprised at GCC being slower than clang. I would have thought that GCC, which had a 20? year head start would've made faster code. And yet, occasionally I look into the assembly and go "what are you doing?" And the same flags + source into clang is better optimized or uses better instructions or whatever. One time it was bit extraction using shifts. Clang did it in 2 steps: shift left, shift right. GCC did it in 3 I think? I think it maybe shifted right first or maybe did a logical instead of arithmetic and then sign extended. Point is, it was just slower.
- stmw 10mo agoCompiler know-how and resources available during compilations made very signicant progress between gcc and LLVM/clang era. gcc was and is an incredible achievement, but it is traditionally considered difficult to implement many modern compiler techqniques in it. It's at least unpleasant, let's put it this way.
- uecker 10mo agoNot sure whether this is generally true. GCC appears to have similar optimizations and I personally find LLVM's code much more intimidating. But it is certainly true that LLVM seems to see more investment. I assume the license may also play a role. For comparison, here is some related code: https://github.com/gcc-mirror/gcc/blob/master/gcc/tree-chrec.cc https://github.com/gcc-mirror/gcc/blob/master/gcc/tree-chrec... https://github.com/llvm/llvm-project/blob/release/21.x/llvm/lib/Analysis/ScalarEvolution.cpp https://github.com/llvm/llvm-project/blob/release/21.x/llvm/...
- saagarjha 10mo agoGCC has almost the same modern compiler techniques implemented.
- fweimer 10mo agoDid it involve bitfields? GCC is notoriously bad at optimizing them. There are some target-specific optimizations, but pretty much nothing in the middle-end.
- Neywiny 10mo agoIt did, yes. On an architecture without bit field extracts.
- saagarjha 10mo agoGCC and Clang are largely similar when it comes to performance as each implements passes the other does not. It’s always possible to find examples where they optimize a piece of code differently and one comes out ahead of the other.
- userbinator 10mo agoI'm not. GCC started out as a work of idealistic licensing purists and was deliberately "obfuscated" to make it hard to extend and embed. That stance has since been softened considerably, but the code generator is still far more complex than it needs to be, and I think that has made it harder to modify for efficiency. Clang is far less ideology-focused and its structure makes implementing optimisations easier. On the other hand, I find MSVC and especially ICC output to be quite decent, although I have never seen their source code. Having inspected the output of compilers for several decades, it's rather easy to tell them apart.