Idea: Introduce mode to add cost-centers post-simplification
Currently cost centers are added by the desugarer. Furthermore, the simplifier tries hard to preserve cost-center ticks, even at the expense of optimisation opportunities. This leads to some programs (particularly those that rely on fusion and other deep simplifications) behaving quite differently (e.g. see #12205) under the cost-center profiler than in a "vanilla" build.
However, the cost-center profiler is nevertheless quite useful. One way in which we could preserve the utility of the cost-center profiler while reducing its impact on optimisation is to introduce cost-centers later in the compilation pipeline. For instance, we could rather instruct the desugarer to decorate the AST with source notes (which the simplifier has considerably more lee-way in shuffling about) and then later (e.g. prior to CorePrep) use these to introduce cost centers.
The question, of course, is deciding which cost-centers are worth introducing; afterall, source notes are far too numerous to include them all.
My first guess would be to start with just top-level functions and sufficiently "large" local let
bindings (e.g. perhaps measured by term-size) and see what sort of profiles this gives rise to.