https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114855
--- Comment #58 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:4ba4165d66b18d7c5b8af02ecdf38bfa0690c106 commit r15-4017-g4ba4165d66b18d7c5b8af02ecdf38bfa0690c106 Author: Richard Biener <rguent...@suse.de> Date: Thu Sep 26 11:43:21 2024 +0200 tree-optimiztation/114855 - profile prediction slowness The testcase in PR114855 shows profile prediction to evaluate the same SSA def via expr_expected_value for each condition or switch in a function. The following patch caches the expected value (and probability/predictor) for each visited SSA def, also protecting against recursion and thus obsoleting the visited bitmap. This reduces the time spent in branch prediction from 1.2s to 0.3s, though callgrind which was how I noticed this seems to be comparatively very much happier about the change than this number suggests. PR tree-optimization/114855 * predict.cc (ssa_expected_value): New global. (expr_expected_value): Do not take bitmap. (expr_expected_value_1): Likewise. Use ssa_expected_value to cache results for a SSA def. (tree_predict_by_opcode): Adjust. (tree_estimate_probability): Manage ssa_expected_value. (tree_guess_outgoing_edge_probabilities): Likewise.