Compiler Explorer
godbolt.org
godbolt.org
2018 https://news.ycombinator.com/item?id=18671993
2016 https://news.ycombinator.com/item?id=13182726
2016 (a bit) https://news.ycombinator.com/item?id=12627295
2016 https://news.ycombinator.com/item?id=11671730
2015 https://news.ycombinator.com/item?id=9861294
It is so neat to have this smorgasbord without needing to install emulators or containers with toolchains, or worse, acquire all of the relevant hardware as in the old old days.
As a compiler writer, I find this useful when I have an "oh crap" moment and need to find a simple C program to generate specific IR, or I need to find the IR of a simple C program. Despite literally having a built tip-of-trunk compiler that I'm working on. It's that convenient.
I post those links because many users like to read older threads. Still looking for brief unambiguous wording to make that clear... "if curious see also" is still leading to some misunderstandings.
"Optimizations in C++ Compilers (acm.org)" https://news.ycombinator.com/item?id=23822044 (102 points, 23 days ago, 20 comments)
An alternative would be for the compiler to generate a stub function (can be shared across all classes for cases where the same vtable offset is used, unless your architecture has some very exotic calling convention) that jumps to a fixed offset in the vitable, and use a skinny pointer to that stub as a virtual member function pointer, but that's not the usual implementation.
In any case, calling through a pointer to virtual member function has to perform virtual dispatch unless the compiler can statically constrain the runtime type of *this being used at the call site. Remember that C++ needs to allow separate compilation, so without a full-program optimizer that breaks dlopen(), C++ can't perform devirtualization on non-final classes.
Making the class final will allow the compiler to statically constrain the runtime type and devirtualize the pointer to member function call.
Edit: added paragraph break.
Now I think I finally understand why MSVC pointer to member functions are 16 bytes wide; I knew about the multi-inheritance this pointer adjustment, but I actually had no idea about virtual dispatch through member pointers. Frankly, I never used them in a way that would’ve mattered for this.
The problem is that most devs don't bother with PGO.
For example, you can see gcc's progression of efficiency for c atomics with https://godbolt.org/z/brsoEr. If you increment the gcc version number, you will see the (very slow) mfence disappear, and xchg show up.
Then there is Clang at O3: If an int falls in the forest, and there is no one around, was it ever incremented? No. The function turns into a bare ret.
GCC seems to eliminate them since at least 4.7.1.
If the memory access (load or store) itself is the desired behavior, you better make sure you add volatile, even to atomic<int> types. The atomic<> simply provides certain guarantees about atomicity of that access in regards to other accesses within the same process, not about access from different process. If the compiler analysis determines that the atomic<> store/load isn't necessary within the currently compiled program, than it may completely elide it.
I think GCC may be disabling certain optimizations on atomic<> access because many people mistakenly use atomic<> for interprocess communication and it would break that code?
For a random example from a few days ago, I wanted to understand how Rust compiles various approaches to doing pairwise addition between a f64 vector and a f32 vector: https://godbolt.org/z/9envsT. Profiling can tell me which is fastest, but godbolt is really helpful for understanding why.
(Fun fact I learned recently, after years of using it: Godbolt is named after its creator, Matt Godbolt [0]).
The thing is that he originally served it from its domain so people use both interchangeably.
And it still is, right? Or is there also a Compiler Explorer domain?
No other sticker has quite the cachet of a Godbolt sticker.
By the way, what I think could make this tool more useful for the average user is if the assembly were decompiled into another language (like C).
It's somewhere in the ideas list... https://github.com/compiler-explorer/compiler-explorer/issue...
Something similar is Andreas Fertig's awesome https://cppinsights.io/
We also have a REST API:
$ curl -s https://godbolt.org/api/languages Id | Name go | Go c | C fortran | Fortran c++ | C++ cppx | Cppx assembly | Assembly cuda | CUDA python | Python llvm | LLVM IR d | D ispc | ispc analysis | Analysis nim | Nim rust | Rust clean | Clean pascal | Pascal haskell | Haskell ada | Ada ocaml | OCaml swift | Swift zig | Zig⏎
It's pretty cool being able to compare equivalent programs in different languages.