4 ms·
How to keep the O3 goodness without pessimizations: Use likely/unlikely liberally, unreachable(), and PGO. If the code slows down, it's usually because the com
by mhh__ 5y ago
How to keep the O3 goodness without pessimizations: Use likely/unlikely liberally, unreachable(), and PGO.
If the code slows down, it's usually because the compiler has generated a bunch of code because it doesn't know what hot path to schedule for.
They will generate hundreds to thousands of instructions for factorial if you let them because it turns it into a loop, then vectorizes the loop.
Undefined Behaviour pub quiz question in there ^^
- MauranKilom 5y agoNot sure if that would have an impact here. GCC is just unaware of the latency implications of store forwarding. I mean, it's definitely worth a shot, but you'd just be more or less hoping that your mentioned techniques disable the right optimization pass.
- mhh__ 5y agoThat's true, although I'm curious if any compiler really understands the microarchitecture at that level without being coerced by a compiler dev writing a pass (i.e. won't happen straight from a pipeline description)
- gnufx 5y agoYes to -fprofile-use. That brought gfortran to essentially the same geometric mean as ifort with reasonable "good" flags for me, running a benchmark set which I think is supposed to show off proprietary compilers. ifort got little benefit from its equivalent.
- deleted 5y ago[deleted]
- unwind 5y agoJust to clarify, in this context PGO = Profile-Guided Optimization [1]. [1]: https://en.m.wikipedia.org/wiki/Profile-guided_optimization https://en.m.wikipedia.org/wiki/Profile-guided_optimization
- jhgb 5y ago...as opposed to? Off the top of my head I can't seem to remember a single acronym I could possibly confuse it with, and now you got me wondering which common acronym I completely failed to learn.
- bick_nyers 5y agoDo you know of any tools for generating this, possibly with runtime data? Been wanting to do this ever since I learned about the feature but I don't want to do this by hand for dependencies. Edit: It is possible that I just don't understand how to actually implement PGO
- gnufx 5y agoI don't know what exactly is required, but the basic business is gcc -fprofile-generate ... ./a.out ... gcc -fprofile-use ... I don't know the current state of https://gcc.gnu.org/wiki/AutoFDO https://gcc.gnu.org/wiki/AutoFDO