Inspecting compiler optimizations


#1

I watched this really nice talk by Sean Griffin where he shows, among other things, how code gets optimized by the compiler – function calls get inlined or even completely compiled out if they turn out not to yield a useful result. It got me wondering whether there’s a tool that will show me these successive optimizations applied to my code (or lack thereof), or whether it’s something that I just have to work out on my own by becoming more intimately acquainted with the compiler?


#2

Most popular C/++ compilers provide this feature to some extent (e.g. -fopt-info for GCC, -Rpass and friends for clang), however you usually want to narrow the output down to a tiny region of the code and a specific kind of optimization, as the amount of decisions which a compiler’s optimizer takes on a normal program is huge and you will get overwhelmed by the corresponding terminal output.

I don’t have the direct answer to your question of whether this feature exists in rustc though.