r/programming • • May 10 '20

Make LLVM fast again

https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html
138 Upvotes

91 comments sorted by

View all comments

Show parent comments

25

u/AlexReinkingYale May 11 '20 edited May 11 '20

I just kind of think the author is misguided here. If llvm is looking to be competitive as a backend for production C and C++, there's just really no such thing as "good enough". A lot of the use cases of C and C++ always want better performance. For good enough performance, there's just about every other language and framework. If you've tied your wagon to something so intertwined with the C++ ecosystem, you should go into it with this knowledge.

This might be a bit controversial, but as a high-performance computing researcher and compiler constructor myself, I agree with the author for the most part. If you need absolute maximum performance, you either shouldn't expect your compiler to give it to you or you shouldn't be writing in C/C++.

Here's what good enough means: the compiler's output won't bottleneck your optimization efforts. And this is mostly true. No matter what sort of application you're writing, the quality of LLVM's output is so high that the most important optimizations come from large-scale reorganizations of computation and resource loading, full stop.

Discovering these reorganizations in a setting as unconstrained as C/C++ just isn't possible. The set of legal optimization steps depends on the particulars of the program that a general-purpose compiler isn't able to reason about. Even if it could, the space is so large that there's no way to explore it. Even if it could do that, the fastest program might not even be reachable from a series of legal steps. Eventually you'll need to assume your compiler can solve the halting problem.

So the alternatives are to either painstakingly write assembly, or encode the particulars of the problem you're trying to solve in a domain-specific language. In a well-designed DSL, the space of allowable optimizations is much more targeted and you can push your performance much farther than you can in C/C++ alone.