logoalt Hacker News

Neywinyyesterday at 6:07 PM4 repliesview on HN

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.


Replies

saagarjhayesterday at 10:45 PM

GCC 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.

stmwyesterday at 7:16 PM

Compiler 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.

show 2 replies
userbinatortoday at 4:26 AM

I'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.

fweimeryesterday at 8:21 PM

Did it involve bitfields? GCC is notoriously bad at optimizing them. There are some target-specific optimizations, but pretty much nothing in the middle-end.

show 1 reply