3 ms·
To summarise: Use Python to output LLVM intermediate representation (IR) and then compile the IR. C was created in the PDP-11 era whereas LLVM IR was designed
by ChrisSD 8y ago
To summarise: Use Python to output LLVM intermediate representation (IR) and then compile the IR.
C was created in the PDP-11 era whereas LLVM IR was designed for more modern processors, so coding in the latter allows for more performance optimisations that C compilers can't always make.
- stochastic_monk 8y agoIs gcc’s IR fundamentally limited compared to LLVM’s somehow? I see better assembly generated by each for different cases.
- codeflo 8y agoI don't think so, and even where it would be, GCC's IR can evolve. But GP was talking about the limitations of C, not GCC. C's memory model puts some limits on what a compiler can do that other languages might not. Fortran is usually given as an example of a language that can be faster than C, because the compiler is allowed to do more. Rust might get there as well, at least in very specific circumstances. Given that GCC also has a good Fortran frontend, I'd assume that their IR is already more powerful than what's needed to compile C alone.
- celrod 8y agoIsn't it just that it is hard to prove there's no aliasing in C, which can make it harder to vectorize? If so, "restrict" should handle that in most cases.
- marcosdumay 8y agoI imagine the reason everybody chooses the LLVM's IR is because the GCC one isn't stable.
- gnulinux 8y agoLLVM IR is a moving target too.
- loeg 8y agoIn other words: Use Python to create a domain-specific compiler that essentially unrolls the entire problem and feeds it into LLVM. LLVM is able to optimize that better than the C or C++.
- pjmlp 8y agoIBM used a LLVM like architecture to do RISC research during the 70's. "An overview of the PL.8 compiler" http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.453.5277&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.453...
- jcranmer 8y agoI noted at https://news.ycombinator.com/item?id=19014504 https://news.ycombinator.com/item?id=19014504 that this benchmark is basically a garbage benchmark because it's not properly comparing apples to apples. It doesn't even manage to use LLVM's optimizations on the IR properly, which should raise major red flags about how valid the comparison is. Besides that, LLVM IR is not all that different from C. LLVM essentially originated as an implementation of the abstract machine described in the C standard, and most of the semantics of LLVM essentially align with the equivalent semantics in C. There are some additions for things that don't exist in C--bitcast, vector types, unwinding/exception handling--and there are knobs to turn down some of the undefinedness in C (e.g., you can choose whether or not integer overflow causes undefined behavior, and you can vary the alignment of load and store operations). But using LLVM IR directly isn't going to expose any extra optimization opportunities that you couldn't have already expressed with C, potentially with some extra gcc-isms (such as vector types).