Hacker News new | ask | show | jobs
by mdiep 5198 days ago
Is there a reason I should care about GCC anymore? Admittedly, I mostly code ObjC on OS X, where GCC is no longer relevant, but LLVM seems to have leapfrogged GCC so dramatically that I'm unsure why I would even care about GCC.

LLVM integrates better with tools, has an amazing static analyzer, and AFAIK generates code that is on average as fast and small as GCC. (I believe who wins depends on the code.)

2 comments

I'd say that in 9 out of 10 GCC creates faster code than LLVM/Clang (I see typically 5-10% difference in performance oriented code), add to this that LLVM/Clang lacks strong special optimization strategies like PGO (profile guided optimization) then it's a clear win for GCC. GCC also supports more languages and architectures than Clang which simply mirrors the needs of Apple (ObjC, C, C++). If you are on OSX then yes, there's likely little reason for you to use GCC since OSX ships with a (5 year?) old GCC version and also obviously because Clang/LLVM integrates much better with Apple's proprietary XCode.

That said I use both, and at work we test our code against both toolchains (and some other compilers aswell). The static analyser in Clang is a welcome addition and the error diagnostics/reporting is top notch so it certainly has strong features even though it falls behind GCC in code optimization.

Since 3.0 added greedy register allocation and LLVM SVN just added better intrinsics for SSE and AVX, I've seen LLVM SVN from the last few weeks pull ahead of GCC 4.6.2 in quite a few personal projects for high performance C++ whereas before that, as you say, GCC was pretty much always ahead.

However, GCC 4.7's just around the corner and I haven't tried that yet...

PGO will probably come to LLVM soon, for what it's worth. They added branch probability and basic block frequency support in 3.0 with an eye towards it, anyway.
Great, yes there's been propositions made towards it for quite some time but no actual code so I was almost thinking it wouldn't happen, here's hoping it will happen now. Every other major compiler I can think of has it, GCC, ICC, Open64, MSVC, and the optimization often has a great impact on performance dependant code.
If your only reason for using gcc is speed and you're on a Linux platform, you should really try out icc. The loop unrolling and vector op generation are much better than gcc's (at least for code we've tested on, YMMV) and can result in some really big speedups.

Though, admittedly, if speed is an issue you probably have already manually loop-unrolled and used the gcc compiler intrinsics.

I have and yes ICC generally won on our tests but:

A) it's proprietary, I have no interest in relying on a proprietary toolchain (and from what I gather neither does the company I work for)

B) it supports a very limited range of cpu architectures, not only is it directly tailored for Intel cpu's it even has a history of selecting poor code paths for AMD cpu's.

As for manual loop unrolling, for alot of code PGO does a great job here by unrolling based on the statistics gathered during the first pass. In fact GCC's pgo seems to do a better job than ICC's pgo implementation, ICC's lto beats GCC's on the other hand, and of course ICC does a better job at vectorization and has better optimized math functions.

Is there a reason I should care about LLVM anymore? I mean, I mostly code C and C++ on Linux, where no distros build with LLVM and it isn't yet relevant.

Yawn. LLVM seems nice. When it competes on merit in the big world instead of in a sandbox people will care more I guess. Last I tried building my C++ project with it, it puked on the STL headers.

Use what you like.

What makes you think GCC 5.0 tomorrow will be better supported by your current development environment, than LLVM today?

I find the rest of our comment somewhat derogatory towards LLVM and the kind of things you can do with it today, it's already at a point where it provides comparable compatibility and features as the many different GCC versions you'll find on various unix systems. Somehow every time I read something about LLVM here people start to rant about some incompatibility they've seen that GCC doesn't have, as if GCC is the epitome of compilers. From experience I can tell you LLVM shows better compatibility with current GCC versions, than many older GCC versions that are still shipped with some Linux distro's.

Eventually, unless GCC makes a giant leap forwards in all the ways set forth in this article, LLVM is going to replace it, sooner or later. I think that's what the guy above me was about when he asked why GCC is still relevant today.

If LLVM is better supported in the future then great: I'll use it and care about it. It's not. That was my point. GCC is supported, so I (have to) care about it. And I'm not talking out of ignorance here. I try LLVM regularly. Clang++ as of a development snapshot of a few months ago couldn't compile the STL headers shipped with the gcc on Fedora 16 (or 15, don't remember), so it can't compatibly be used for C++ development on my platform.

So no, I don't really "care" about it. Fix the compiler to actually be better for my purposes than what I have before telling me what I should use or care about please. And when you do, I promise I'll join your little cult, OK?

>What makes you think GCC 5.0 tomorrow will be better supported by your current development environment, than LLVM today?

Define 'current development environment', both at home and at work GCC is the primary development environment for me as far as compilers go, I'm not waiting for GCC 5.0, I am using GCC 4.6 today.

>comparable compatibility

Is a very fuzzy statement, having compiled lots of open source projects under many different compilers there are certainly many projects out there which fails to compile with Clang (but it's certainly making fast progress in compability). Granted most if not all of these packages were written against GCC and some of them may use GCC extensions Clang/LLVM does not yet (or in some cases won't) support or some other quirks which all compilers have in their implementations of different standards.

>Eventually, unless GCC makes a giant leap forwards in all the ways set forth in this article, LLVM is going to replace it, sooner or later. I think that's what the guy above me was about when he asked why GCC is still relevant today.

Been hearing that ever since LLVM (and later Clang) surfaced as an option, I'd say you'll have to set your hopes for 'later' (Clang's been around what? 4 or 5 years now?). Personally I can't see why anyone other than someone with an agenda would want either compiler to disappear, competition means better tools for us end users, no matter which toolchain we prefer.

As for modularization, that has been an ongoing task in GCC long before this particular mailing list discussion, and I think it will continue as it has now in small steps.

I'm not saying I'd like to see GCC disappear. In fact, I still depend on it for all of our C++ stuff. The point I was trying to make is that GCC isn't that much better than LLVM in terms of how well it compiles every bit of valid C++ you throw at it. At least not if you have to compile the same code base across multiple different OS and GCC versions.

LLVM is not as good as GCC in some ways, but evidently better and more future-proof in others. Unless GCC evolves in the same direction as Clang + LLVM, the latter will close the gap sooner or later and basically deprecate GCC. I'm not advocating this should happen, not even predicting it will, just observing GCC is starting to fall behind in exactly the areas that make LLVM so useful.

> Been hearing that ever since LLVM (and later Clang) surfaced as an option, I'd say you'll have to set your hopes for 'later' (Clang's been around what? 4 or 5 years now?)

Well, it already replaced GCC on probably one of the most popular platforms for current development, so you can't say it isn't getting anywhere, can you? It's going to get interesting when we see some kind of Gentoo fork that uses it by default. That would be a good indication it is very nearly mature enough to challenge GCC on all aspects.

>Well, it already replaced GCC on probably one of the most popular platforms for current development

Incidentally the owner of that platform is also the main (sole corporate?) driving force of Clang/LLVM and has a history of wanting to incorporate open source into their proprietary tools which doesn't work with GPL licenced code. In other words saying that Apple is switching to Clang/LLVM makes no bigger point in my opinion than saying that FSF uses GCC.

Apple uses LLVM to drive the very sophisticated auto-completion, static analysis, and error reporting features built into XCode, which are by any standard insanely good. No need to get politics or hidden agenda conspiracy theories along for the ride.

Also, I think you should invest a little time finding out what LLVM is used for besides as the backend for the compiler Apple uses. Apple maybe the only heavyweight driving the development of Clang/LLVM, but it is definitely not the only one using or profiting from it.

"Eventually" and "Is there a reason I should care about GCC anymore" don't mix well for me. Time will tell; GCC is definitely not out of the game.

That said, having a C++ compiler designed for humans and not robots is to be commended.

So I guess the best choice is to develop with clang for better error reporting and support tools and do the final production build with gcc for optimizations :)
Apple's entire toolchain is now built on LLVM, AFAIK. Hobby and research languages/efforts by the dozen build on LLVM.

LLVM is where the innovative ecosystem lives now, even if GCC is more reliable for just churning out fast C code.