The profile mismatches uncovered by my merge_blocks change are actually caused
by tree-ssa-dce not updating profile of blocks with no statements for whose it
optimized away control dependencies. In most cases those basic blocks are
merged or skipped as forwarders. I tried to simply set their count as
uninitialized but that upsets verifier since in some cases we keep the block
around (for example, when it is header of a loop).
In all cases I debugged we optimized away an unnecesary loop and while merging
old code picked porfile of loop preheader, while we now pick loop header. This
is however not guaranteed and we may process blocks in different order and pick
wrong profile.
Since regions of dead basic blocks must be acyclic it is easy to propagate the
frequencies as implemented by this patch.
Bootstrapped/regtested x86_64-linux. Comitted
gcc/ChangeLog:
PR middle-end/122122
* tree-cfgcleanup.cc (tree_forwarder_block_p): Cleanup.
* tree-ssa-dce.cc (propagate_counts): New function.
(eliminate_unnecessary_stmts): Use it.