Btw is it correct to assume there must be a (thin) set of optimizations which are a net win over -O0? With all the stack spilling etc going on there should be quite some compilation time to be saved regarding codegen and debug info generation in exchange for that optimization time?
While this is slightly off-topic, thereās certainly room for a middle ground of running a dozen or so of the basic optimizations (most notably mem2reg, sroa, instcombine) without running the full ~70 passes that run at O1. As noted above, O1 takes ~1.79x longer to compile than O0 and finishes executing benchmarks in ~0.31x the time; if you want to experiment with finding a configuration in the middle of this, Iād recommend starting by running only the āO1 Function Simplification Pipelineā (see PassBuilderPipelines.cpp
), and either bringing in passes from the āModule Optimization Pipelineā if the resulting execution time is too slow, or further removing passes from the simplification pipeline if the compile time is too slow.
+@echristo who did some -O1 function simplification pipeline tuning a while back.
There are still a couple passes in PassBuilder::buildModuleSimplificationPipeline
that you want to run before the function simplification pipeline, e.g. EarlyFPM
cleans up the output of the frontend first.
The module optimization pipeline probably shouldnāt be run if you want a good debugging experience, it performs many optimizations that arenāt necessarily simplification that can make the resulting code more complicated.
I agree with @MaskRay that we should hold off on the -O2g
. Adding -fextended-lifetimes
to -Og
however makes sense. As a compromise, we could add a -fno-extended-lifetimes
option for those that want to claw back the time difference due to the extended lifetimes. AIUI, -Og
makes no guarantees about compile times, so relying on that for the compile time difference is not sound.
-fno-extended-lifetimes -Og
is basically -O1
, at least right now with this proposal. Iād hold off on adding flags until people really need to choose granularity between -Og
and -O1
.
Correct, it is equivalent to -O1
for now. I wonder if that is something that we should be relying upon though. The -fno-
variant of the flag is just a boolean flag in the TableGen definition and doesnāt really add much complexity IMO (as it is a pretty common pattern to implement both at the same time).