4 ms·
Does profile-guided optimisation really 'hone in on the parts of a program which will most benefit from optimisation' ? I thought that all it really did, at le
by joosters 9y ago
Does profile-guided optimisation really 'hone in on the parts of a program which will most benefit from optimisation' ?
I thought that all it really did, at least on gcc, was record which branches were taken and optimise the code to reflect the common path. Do compilers really make use of the profile timings to decide to spend more time optimising 'hot' parts of the code with more involved/expensive transformations?
- sanxiyn 9y agoNot explicitly, but because hot functions get inlined and inlining enables optimizations, something roughly similar does happen.
- greglindahl 9y agoPGO can also record loop sizes, which helps with decisions about vectorization, prefetching, non-temporal stores, etc etc. Call counts are useful for inlining and function specialization decisions. I don't know what gcc does, but Open64 does all of the above.
- Joky 9y ago> Do compilers really make use of the profile timings to decide to spend more time optimising 'hot' parts of the code with more involved/expensive transformations? Clang does not AFAIK.
- bzbarsky 9y agoLast I checked, gcc in PGO mode can basically do things like "-O2 for hot code, -Os for everything else". MSVC in PGO/LTO mode will do all sorts of exciting things. For example, in hot code it will detect that a virtual function call is always or nearly always happening with the same vtable pointer and emit a guard on the vtable pointer followed by an inlining of that one particular implementation (with a fallback to a normal virtual call if the guard fails). I'm pretty sure it doesn't do this for all virtual function calls in the program. Even if it only does it for ones where it has "enough data", that would bias towards the hot ones.