From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 57E433882078; Fri, 30 Jun 2023 16:18:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57E433882078 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688141894; bh=yEexeKzdnl4hoSy0nLDeCVttlRHNeKDjKiDlpVzMPJ8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OOkC8HqCODEI4ZF1EkEJYqTE6CRN54TYZ0Auckk3gTgcGGFH8lj/NaKdK9gdAH5kr fpe6vzLdy9pWQiLYzDxKkSaelqOGM7GkQ1FlgZZMB/3OiwW/7UskJfa0/J0LGokHXp HWshgaJTEJ5seRL5wAOz2BZ9WvgNw2ivBL0khoKs= From: "hubicka at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103680] Jump threading and switch corrupts profile Date: Fri, 30 Jun 2023 16:18:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: internal-improvement, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: hubicka at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103680 --- Comment #10 from Jan Hubicka --- I am testing: diff --git a/gcc/cfg.cc b/gcc/cfg.cc index 897ef534ff5..defdf679f7b 100644 --- a/gcc/cfg.cc +++ b/gcc/cfg.cc @@ -922,7 +922,6 @@ update_bb_profile_for_threading (basic_block bb, fprintf (dump_file, "bb %i count became negative after threading", bb->index); } - bb->count -=3D count; /* Compute the probability of TAKEN_EDGE being reached via threaded edge. Watch for overflows. */ @@ -934,8 +933,8 @@ update_bb_profile_for_threading (basic_block bb, { if (dump_file) { - fprintf (dump_file, "Jump threading proved probability of edge " - "%i->%i too small (it is ", + fprintf (dump_file, "Jump threading proved that the probability of edge " + "%i->%i was originally estimated too small (it is ", taken_edge->src->index, taken_edge->dest->index);=20=20= =20=20 taken_edge->probability.dump (dump_file); fprintf (dump_file, " should be "); @@ -945,6 +944,8 @@ update_bb_profile_for_threading (basic_block bb, prob =3D taken_edge->probability.apply_scale (6, 8); } + bb->count -=3D count; + /* Now rescale the probabilities. */ taken_edge->probability -=3D prob; prob =3D prob.invert (); This fixes the trivial testcase in comment #9=