https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115144
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <rgue...@gcc.gnu.org>: https://gcc.gnu.org/g:5b9b3bae33cae7fca2e3c3e3028be6b8bee9b698 commit r15-815-g5b9b3bae33cae7fca2e3c3e3028be6b8bee9b698 Author: Richard Biener <rguent...@suse.de> Date: Wed May 22 09:16:51 2024 +0200 tree-optimization/115144 - improve sinking destination choice When sinking code closer to its uses we already try to minimize the distance we move by inserting at the start of the basic-block. The following makes sure to sink closest to the control dependence check of the region we want to sink to as well as make sure to ignore control dependences that are only guarding exceptional code. This restores somewhat the old profile check but without requiring nearly even probabilities. The patch also makes sure to not give up completely when the best sink location is one we do not want to sink to but possibly then choose the next best one. PR tree-optimization/115144 * tree-ssa-sink.cc (do_not_sink): New function, split out from ... (select_best_block): Here. First pick valid block to sink to. From that search for the best valid block, avoiding sinking across conditions to exceptional code. (sink_code_in_bb): When updating vuses of stores in paths we do not sink a store to make sure we didn't pick a dominating sink location. * gcc.dg/tree-ssa/ssa-sink-22.c: New testcase.