On Thu, Oct 2, 2025 at 12:38 PM H.J. Lu <[email protected]> wrote: > > Hi Jan, > > I didn't find > > https://gcc.gnu.org/cgit/gcc/commit/?id=8498ef3d075801 > > in > > https://gcc.gnu.org/pipermail/gcc-patches/2025-October/date.html > > In any case, your commit caused: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122122 > > -- > H.J.
If the second basic block is empty, ignore its profile count. Copy the second basic block profile count only if the first basic block profile count isn't initialized. PR middle-end/122122 * cfghooks.cc (merge_blocks): Ignore the profile count of the empty second basic block. Copy the second basic block profile count only if the first basic block profile count isn't initialized. I am testing this patch. OK for master if there are no regressions? -- H.J.
From 713a8496b6dc306efb54b3f974cd48ead155a47c Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <[email protected]> Date: Thu, 2 Oct 2025 14:03:14 +0800 Subject: [PATCH] Ignore the empty second basic block If the second basic block is empty, ignore its profile count. Copy the second basic block profile count only if the first basic block profile count isn't initialized. PR middle-end/122122 * cfghooks.cc (merge_blocks): Ignore the profile count of the empty second basic block. Copy the second basic block profile count only if the first basic block profile count isn't initialized. Signed-off-by: H.J. Lu <[email protected]> --- gcc/cfghooks.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/gcc/cfghooks.cc b/gcc/cfghooks.cc index 8b3346898aa..803850b7852 100644 --- a/gcc/cfghooks.cc +++ b/gcc/cfghooks.cc @@ -817,14 +817,18 @@ merge_blocks (basic_block a, basic_block b) if (!cfg_hooks->merge_blocks) internal_error ("%s does not support merge_blocks", cfg_hooks->name); - /* Pick the more reliable count. If both qualities agrees, pick the larger - one since turning mistakely hot code to cold is more harmful. */ - if (a->count.initialized_p ()) - a->count = b->count; - else if (a->count.quality () < b->count.quality ()) - a->count = b->count; - else if (a->count.quality () == b->count.quality ()) - a->count = a->count.max (b->count); + if (!empty_block_p (b)) + { + /* Pick the more reliable count. If both qualities agrees, pick + the larger one since turning mistakely hot code to cold is more + harmful. */ + if (!a->count.initialized_p ()) + a->count = b->count; + else if (a->count.quality () < b->count.quality ()) + a->count = b->count; + else if (a->count.quality () == b->count.quality ()) + a->count = a->count.max (b->count); + } cfg_hooks->merge_blocks (a, b); -- 2.51.0
