News for hackers. Stuff that matters.
Re:Make LLVM Fast Again by londons_explore on Monday May 11, 2020 @04:13AM (#23139931)
Am I the only one who wants to see a split into a "fast compile" mode and a "spend hours making every optimization possible" mode?

Most code is executed a lot more frequently than it is compiled, so if I can get a 1% speed increase with a 100x compile slowdown, I'll take it.

I don't want to see good PR's that improve LLVM delayed simply because they cause a speed regression.

Re:Make LLVM Fast Again by fluffything on Monday May 11, 2020 @09:24AM (#23141831)
You can already spend as much as you'd like on optimizations if you are using LLVM. Just use a superoptimizer [0]:

    clang -Xclang -load -Xclang libsouperPass.so -mllvm -z3-path=/usr/bin/z3
, or increase the inlining heuristics..., or just create your own optimization strategy like rustc does [1], or...

LLVM is super configurable, so you can make it do whatever you want.

Clang defaults are tuned for the optimizations that give you the most bang for the time you put in, while still being able to compile a Web browser like Chrome or Firefox, or a whole Linux distribution packages, in a reasonable amount of time.

If you don't care about how long compile-times take, then you are not a "target" clang user, but you can just pass clang extra arguments like those mentioned above, or even fork it to add your own -Oeternity option that takes in your project and tries to compile it for a millenia on a super computer for that little extra 0.00001% reduction in code size, at best.

Because often, code compiled with -O3 is slower than code compiled with -O2. Because "more optimizations" do not necessarily mean "faster code" like you seem tobe suggesting.

[0]: https://github.com/google/souper [1]: https://github.com/rust-lang/rust/blob/master/src/rustllvm/P...

Re:Make LLVM Fast Again by noch on Monday May 11, 2020 @07:45PM (#23148796)
> Because often, code compiled with -O3 is slower than code compiled with -O2. Because "more optimizations" do not necessarily mean "faster code" like you seem tobe suggesting.

Indeed, due to patterns of resource use and availability (e.g. the memory wall[0]), compiler optimisations can only solve 1-10% of performance problems a piece of code might have. To paraphrase Mike Acton: The vast majority of your code consists of things the compiler can't reason about.[1]

[0]: https://en.m.wikipedia.org/wiki/Random-access_memory#Memory_...

[1]: [Mike Acton, "How to Write Code the Compiler Can Actually Optimize", GDC2015.](https://m.youtube.com/watch?feature=youtu.be&v=x61H6qEtK08&t...)

Re:Make LLVM Fast Again by CalChris on Monday May 11, 2020 @11:31AM (#23143203)
Has anyone ever done a Pareto frontier analysis on this? Specifically, this would be for speed rather than size.
Re:Make LLVM Fast Again by fluffything on Tuesday May 12, 2020 @09:56AM (#23154014)
What would you expect to learn and how would you do this?

I can't imagine anything useful coming out of it.

Re:Make LLVM Fast Again by worldsayshi on Monday May 11, 2020 @04:18AM (#23139964)
Yeah this seems like two very different use cases. Stating the obvious: when debugging I want as fast builds as possible. When shipping I want as fast software as possible.
Re:Make LLVM Fast Again by bflesch on Monday May 11, 2020 @05:06AM (#23140212)
The only problem being if you want to debug the optimized code ;)
Re:Make LLVM Fast Again by khalladay on Monday May 11, 2020 @07:59AM (#23141171)
This is true a lot in games - often the "debug" version of a game is literally too slow to reproduce issues, so you have to work with the optimized builds.

...even if the actual debugging would be much easier with a debug build.

Re:Make LLVM Fast Again by bluGill on Monday May 11, 2020 @09:05AM (#23141638)
Understood. However even then I would hope that games have unit tests and other module tests that can run just a subset of code and not the entire game. When I'm writing code I want to know it builds and the basics work before I run the entire program.

I work on seasonal programs. I can only do fully realistic tests in the month of April (depending on the weather it shifts a few weeks) , meaning my window to test is closed for the next 11 months. I have learned to find ways to run my code in less realistic situations.

Re:Make LLVM Fast Again by steerablesafe on Monday May 11, 2020 @10:03AM (#23142237)
There are also those bugs that only manifest in the release build.
Re:Make LLVM Fast Again by bluGill on Monday May 11, 2020 @09:07AM (#23141653)
That happens, but fortunately not often. Most problems show up in either optimized or unoptimized code. If it is in optimized code only it is a compiler bug (rare but I have seen it) or a race condition that won't show up in the debugger either. (there are a few more choices but the above are the big ones in my experience)
Re:Make LLVM Fast Again by compiler-guy on Monday May 11, 2020 @10:45AM (#23142671)
In optimized code, it is far more likely that one has a programming error in one's source code that an aggressive optimization revealed, rather than a bug in an industrial compiler. For example, an uninitialized variable that ends up sharing a memory location with some other variable whose life-time doesn't overlap in optimized mode rather than having its own memory location without optimization.

That one is caught be a warning, but there are thousands of possible errors that can be exposed this way.

Compilers have bugs all the time, but code in a write-test-debug-cycle typically has many more.

Re:Make LLVM Fast Again by ludamad on Monday May 11, 2020 @11:18PM (#23150261)
Which is why equally aggressive debug checks are important
Re:Make LLVM Fast Again by egwor on Monday May 11, 2020 @04:19AM (#23139971)
This should be an optimisation that you choose to enable, though, right? It might be prohibitively expensive to run the compile for other reasons (time to do a deploy for a fix, time and cost to run builds for CI etc.) so it has to be something that can be dialled up/down.
Re:Make LLVM Fast Again by simfoo on Monday May 11, 2020 @05:08AM (#23140230)
-O3 should include those expensive optimizations. If you want fast builds with minimal optimizations, go with -O1
Re:Make LLVM Fast Again by 1980phipsi on Monday May 11, 2020 @06:28AM (#23140637)
Does clang have -O0?
Re:Make LLVM Fast Again by GuB-42 on Monday May 11, 2020 @06:37AM (#23140682)
Yes (clang11 documentation)

  -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4
      Specify which optimization level to use:
          -O0 Means “no optimization”: this level compiles the fastest and generates the most debuggable code.
          -O1 Somewhere between -O0 and -O2.
          -O2 Moderate level of optimization which enables most optimizations.
          -O3 Like -O2, except that it enables optimizations that take longer to perform or that may generate larger code (in an attempt to make the program run faster).
          -Ofast Enables all the optimizations from -O3 along with other aggressive optimizations that may violate strict compliance with language standards.
          -Os Like -O2 with extra optimizations to reduce code size.
          -Oz Like -Os (and thus -O2), but reduces code size further.
          -Og Like -O1. In future versions, this option might disable different optimizations in order to improve debuggability.
          -O Equivalent to -O2.
          -O4 and higher
              Currently equivalent to -O3
Re:Make LLVM Fast Again by fnord123 on Monday May 11, 2020 @07:50AM (#23141103)
For fast compiles, in clang, -fsyntax-only parses as quick as possible. Then you have -O{0,1,2,3s} for various levels of optimization.

As for the long baking compile, you have a concept of super compilation which will check the branches and determine if there are any places where a function is called with constants and partially evaluate (similar to partial application / prameter binding, but you get a newly compiled function) the function with those constants frozen. But then it has to determine if the branch elision makes it worth dropping the other versions of the function. It's a cool topic that I researched a lot about a decade ago but I think it's not an area with a lot of active interest in AOT compilers.

https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.50....

http://wiki.c2.com/?SuperCompiler

https://en.wikipedia.org/wiki/Stalin_(Scheme_implementation)

Re:Make LLVM Fast Again by bjoli on Monday May 11, 2020 @04:32AM (#23140037)
Guile scheme is getting a "baseline- compiler for that reason: it will compile fast, but not do any of the fancy CPS things that the regular compiler does.
Re:Make LLVM Fast Again by wallnuss on Monday May 11, 2020 @09:09AM (#23141668)
It all depends on which optimizations you enable and LLVM is very flexible, albeit sometimes you still spend 20% of your time in ISel (Instruction Selection)...
Re:Make LLVM Fast Again by pfdietz on Monday May 11, 2020 @08:28AM (#23141338)
> Most code is executed a lot more frequently than it is compiled, so if I can get a 1% speed increase with a 100x compile slowdown, I'll take it.

Is that really true? I'd have thought most code outside inner loops benefits almost negligibly from optimization.

Re:Make LLVM Fast Again by jeffbee on Monday May 11, 2020 @11:01AM (#23142873)
That really depends on your program. Many servers have sprawling, flat profiles. Most workloads are not computational fluid dynamics. A perspective on hot/cold code ratio is found in "AsmDB: Understanding and Mitigating Front-End Stalls in Warehouse-Scale Computers" https://storage.googleapis.com/pub-tools-public-publication-...
Re:Make LLVM Fast Again by sesuximo on Tuesday May 12, 2020 @11:51AM (#23155356)
Good question. It's worth asking whether optimizations significantly help "most" code.

There are some optimizations that make a big difference everywhere:

- consolidating pure function calls. This can save arbitrary amounts of time. Classic example is strlen being called many times. I know you're not asking about inner loops, but this can change the complexity of loops which is a big big win.

- mem2reg. Kind of self explanatory. Registers are fast but we write C and C++ using addressable objects. Most compilers make a decent effort here even with optimizations turned off.

- global variable numbering. This allows loads and stores to be removed/moved. Often prevents cache misses or puts them off until the end of a function when it doesn't block execution.

- strength reduction. Turning your divisions into shifts. Turning your && into &. Etc. It is not unusual for these peephole changes to save 10s of cycles per instruction replaced.

These are also really fast optimizations (mem2reg can be extremely slow if "optimal", but the heuristic versions that everyone uses are quick).

If you know you won't care, you can mark the function as cold. That said, the compiler might ignore you and decide you cannot possibly really want to disable something like mem2reg.

Re:Make LLVM Fast Again by bluGill on Monday May 11, 2020 @09:19AM (#23141765)
I don't have time to figure out the correct tradeoff for optimization for each tiny code section of code. Just let the compiler do everything and it might be too much but it won't be too little.

Besides, little things add up even outside of tight loops. Slow code in rarely used areas is still noticeable when that rare thing happens.

Re:Make LLVM Fast Again by pfdietz on Monday May 11, 2020 @05:46PM (#23147477)
So, you don't have time to profile to see where the hotspots are, but you care about how fast your program is? Mkay.
Re:Make LLVM Fast Again by jrochkind1 on Monday May 11, 2020 @08:35AM (#23141394)
It may benefit negligibly from optimization -- or rather, the overall program may benefit negligibly from optimizing that code site -- but it's still gotta be executed a lot more frequently than it is compiled right? Unless it has only one or two users, who both compile it all the time, or something.
Re:Make LLVM Fast Again by embrassingstuff on Monday May 11, 2020 @04:30AM (#23140023)
How many people would.use a cloud compiler?

Let's set aside thecnicalities and assume it a real X5 improvements and all the files are mirrored seamlessly.

Re:Make LLVM Fast Again by mrich on Monday May 11, 2020 @06:17AM (#23140567)
If you are referring to a caching distributed compile cluster, most companies with large codebases are using one (or should). It helps a lot and can make the difference between taking half a day for a scratch make (i.e. unusable) to getting down to 10 min.

There are open-source ones but I'm also aware of at least two internal, custom-developed ones.

Re:Make LLVM Fast Again by jingwen on Monday May 11, 2020 @10:48PM (#23150080)
Re:Make LLVM Fast Again by jart on Monday May 11, 2020 @09:06PM (#23149471)
Re:Make LLVM Fast Again by mhh__ on Monday May 11, 2020 @04:47AM (#23140109)
Ken Thompson would be rolling in his grave if not for him being alive.

I could see this having some use in an internal manner for things like game development where you have absolutely enormous codebases (as an abstraction above compile servers and similar).

Re:Make LLVM Fast Again by compressedgas on Monday May 11, 2020 @04:54AM (#23140139)
Many already use one called distcc.
Re:Make LLVM Fast Again by zarkov99 on Monday May 11, 2020 @08:01AM (#23141181)
My company would pay for that, up to $50/developer/month. Its a no brainier if you really get X5 speed improvements, not just for full builds but incremental as well. Of course there are tricky issues there, privacy, lock-in, how intrusive the scheme is, but the build tax in C++ has a very unappreciated impact on productivity, one that the C++ committee seems incapable of addressing.
Re:Make LLVM Fast Again by mrich on Monday May 11, 2020 @09:19AM (#23141760)
I think there is no cloud service for this precisely because companies mostly don't want to give out their source code. Although many already rent AWS instances for their devs :)

In many companies the build cluster runs on the developers' workstations themselves, which has the benefit of fully using idling machines. The drawback is higher maintenance due to less reliability of such machines.

Would your company accept internal hosting for such a cluster, i.e. paying for the hardware themselves?

Re:Make LLVM Fast Again by zarkov99 on Monday May 11, 2020 @09:31AM (#23141897)
In my particular case no, it would be too much hassle for a small business like ours (we are a remote only firm with only a few people). But I can imagine it would make sense when we grow.
Re:Make LLVM Fast Again by jeffbee on Monday May 11, 2020 @11:05AM (#23142911)
There is no cloud service for that ... except Google Cloud Build.
Re:Make LLVM Fast Again by mrich on Monday May 11, 2020 @12:19PM (#23143758)
Are you aware of anyone using it for C++? I couldn't find any mention of C++ in the documentation nor via Googling (sure it will be possible but it seems to involve significant setup)
Re:Make LLVM Fast Again by jeffbee on Monday May 11, 2020 @12:25PM (#23143834)
I'm not really plugged in to the industry. I've used it with bazel cc_binary targets, so I know it works.
Re:Make LLVM Fast Again by pjmlp on Monday May 11, 2020 @09:38AM (#23141969)
Besides the cluster compilers used by C++.

OpenJ9 for Java can use a cloud compiler,

https://blog.openj9.org/2019/05/01/openj9-internship-making-...

.NET when AOT compiled for Windows Store uses cloud compilers, https://blogs.windows.com/windowsdeveloper/2015/08/20/net-na...

And as of Android 10, the cloud compiler is everyone's phone, because PGO data gets uploaded to the play store and improved on each device feedback.

https://android-developers.googleblog.com/2019/04/improving-...

Re:Make LLVM Fast Again by ryanianian on Monday May 11, 2020 @07:13AM (#23140892)
icecream (icecc) is basically this. It’s “cloud” in that it’s distributed, but it requires surprisingly high bandwidth to the cluster, so it basically requires an office LAN connection. Or for your editor to be on that connection a la VSCode’s remote thing.
Re:Make LLVM Fast Again by notriddle on Monday May 11, 2020 @05:15PM (#23147163)
This is probably the other big reason why "cloud compilers" are rare. Not much point in using one if you can compile the source locally more quickly than you can upload it.
Re:Make LLVM Fast Again by londons_explore on Monday May 11, 2020 @04:51AM (#23140128)
MBED already pioneered the cloud compiler.

Their compiler did optimizations to produce (slightly) better code than any compiler you could buy.

A lot of users were uneasy with it.

Re:Make LLVM Fast Again by boomlinde on Monday May 11, 2020 @06:13AM (#23140553)
It's only at link time that object will depend on another, so you don't need a new compiler to support a "cloud" use case where any number of machines can work on compilation.
Re:Make LLVM Fast Again by cwzwarich on Monday May 11, 2020 @10:02AM (#23142235)
A lot of large C++ projects use link-time optimization, since it's the easiest way to get predictably good performance.