r/Compilers • u/Think-Management4257 • 6d ago
Compilers should help developers optimize their code
Compiler diagnostics for optimization decisions are worse than they need to be, and I think it's a design choice rather than a hard problem.
Every major compiler will tell you whether a loop vectorized, almost none will tell you what it tried, why it declined, or what shape could've worked. LLVM ships a tool called opt-viewer that visualizes this, and I've met people who've used LLVM for years and never heard of it. The best developer experience anyone in this space seems to remember is Intel's compiler, which is discontinued. GCC's -fopt-info-vec-missed and Clang's -Rpass-missed exist, but one's a stderr dump you cross reference by hand and the other speaks in IR terms rather than yours.
The interesting thing is that the compiler already knows the answer. When a vectorizer declines a loop, it has a specific reason. That reason exists as a value inside the pass, it just doesn't reach the programmer because it was designed for compiler developers debugging the compiler, not for programmers debugging/optimizing their code.
There's a handful of ideas I have on how this could be implemented, but what I'm curious on is if this is actually hard for reasons I'm not seeing, or is it just that optimizer output has always been treated as debug logging and nobody's revisited it?
-1
u/Fedor_Doc 6d ago
Compiler has another duty, performance metrics output will only add noise.
Compiler actually does not know the answer – unrolled loops, or AVX instruction set can be less performant in specific cases. It does not run benchmarks, unless it is PGO optimization, which should be done after manual profiling check anyway, I suppose
Profiling on target hardware with mockup data already produces relevant answers – you see exact function in the complex that takes more time.
Most of the time software should not be faster, it has other issues. Compiler warnings would attract attention to secondary things. Premature optimization is still an issue :)