Agner`s CPU blog

Software optimization resources | E-mail subscription to this blog | www.agner.org

 
thread Best C++ compiler for Windows - Agner - 2019-09-12
last replythread Best C++ compiler for Windows - Forsen - 2020-09-16
last reply Best C++ compiler for Windows - Agner - 2020-09-16
 
Best C++ compiler for Windows
Author: Agner Date: 2019-09-12 05:33
The number of C++ compilers on the market has gone down in recent years. Several of the less known compilers have gone out of the market, and even the once so popular Borland (Embarcadero) C++ compiler is now no longer maintained. Compiler making has become more complicated with new advanced C++ standards (C++17, C++20), new instruction set extensions such as AVX512 with hundreds of new instructions, and higher standards for code optimization.


Microsoft Visual Studio is very popular because of the user friendly IDE and excellent debugging and cross-reference features. But Visual Studio is lagging behind on support for the latest instruction sets, and it is not the best compiler when it comes to code optimization.


The Intel compiler used to be on the cutting edge of code optimization, but now it has been overtaken by Gcc and Clang. Intel's compiler has also lost in popularity since its hidden "Cripple AMD" function was revealed.


The open source compilers Gcc and Clang have now taken the lead. These two compilers are very similar. Both are supporting all platforms and the newest instruction set extensions.


I have tested the different C++ compilers and listed the results in my C++ manual. The Gcc and Clang compilers are clearly the best when it comes to code optimization. Clang is better than Gcc in several respects, but it has a tendency for excessive loop unrolling, which is a waste of code cache. I must admit that I was quite skeptical of the LLVM/Clang project when it started, but people have put an impressive amount of work into it, and now the Clang compiler can outperform all other compilers on several measures.


Linux and Mac programmers will have no problems finding a Clang compiler. It is a little more complicated on Windows. There are at least two ready-to-use Clang compiler versions for Windows. A Cygwin version and a Visual Studio plugin version.


The Cygwin version of Clang has been around for several years, but it is not fully up to date and it has some performance problems. The Cygwin64 version of Clang is using a medium memory model by default. This is quite wasteful because it will use 64-bit absolute addresses rather than 32-bit relative addresses for static variables and constants. You can improve performance by specifying mcmodel=small. The medium memory model is needed only if you are making a direct link to a variable inside an external DLL (which is bad programming practice anyway). Another disadvantage of the Cygwin version is that you have to include the Cygwin DLL when distributing the executable.


Recently, Microsoft has made a Cygwin build available as a plugin to Visual Studio. My tests show that it produces excellently optimized code. The Cygwin plugin is not yet integrated into the MSBuild framework. It is only supported for the CMake framework, which is quite complicated to use because you have to manually specify a weird mix of Microsoft command line options and Clang options. In fact, I found it more convenient to use the Clang compiler as a command line tool without the Visual Studio CMake framework.


Microsoft have announced that a full integration of Clang into the MSBuild framework will be coming soon. Let's hope that they will deliver on this promise. We will look forward to perhaps the best optimizing compiler integrated to one of the most user friendly IDE frameworks.


On a longer horizon, I suspect that the Clang compiler will eventually replace Microsoft's own compiler. Why would they spend a lot of resources on developing a compiler when it is outperformed by a free and open source compiler anyway. The Visual Studio IDE may still be maintained because it is very useful and a lot or current projects depend on it, even if it will have a different compiler in the back end.


I am more uncertain about the future fate of the Intel compiler. Will they keep maintaining it when fewer and fewer programmers actually use it? There are some very useful function libraries for a lot of specialized purposes that come with the Intel compiler, but these function libraries are working just as well with other compilers.

   
Best C++ compiler for Windows
Author:  Date: 2020-09-16 05:50
@Agner
ICC compiled binaries shouldn't be distributed to AMD users in the first place. If you are not going to target intel cpus specifically, then there is obviously little reason to use this compiler.
It wouldn't be a suprise if LLVM outperforms ICC, even when used on their own architecture. However, due to the lack of proof and showcase, I don't see how this post was helpful.
We need professional comparisions to determine how well ICC performs on intel chips. They offer extra switches for certain lakes, so maybe that can also alter the outcome.
As a sidenote, I read that intel is starting to switch to LLVM (frontent/backend?) with their own optimizations applied (https://www.fz-juelich.de/SharedDocs/Downloads/IAS/JSC/EN/slides/supercomputer-ressources-2019-11/15a-tuning_intel.pdf?__blob=publicationFile). This would make sense to me and if they keep adapting to the ABI of their parent architecture, there should be no problem in compiling extra binaries for different vendors with a compiler that fits, meaning that AMD users execute entirely different PEs.

As for MSVC, I have still encountered a few performance drawbacks, especially in regards of intrinsics and branching. Stuff like that.

   
Best C++ compiler for Windows
Author: Agner Date: 2020-09-16 10:21
@Forsen. Documentation for the comparison of different compilers is in chapter 8.2 of my C++ optimization manual.

Thanks for the information that Intel seems to be switching to the LLVM compiler. This confirms my speculation that we will have fewer compilers in the future.