From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F108C3857728; Wed, 27 Sep 2023 13:21:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F108C3857728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695820874; bh=uX7V0Qd6hDK9SMF82XlvgiynnE0dnbMyFuPpZPtKf08=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wAJ2dw4F4q46HZJ9S7C7hE4axMFu0q8CFuxBi2a11Ag6LGuQqK/Wu/1UeVy32WYps thARSb6LRR4HathNznSCLbe+aKSD0YIOoSHYG2KjFVmFS0wIvIAmBE+zo/5dOOMDrT V4suZbvyyxCaYmT156z67JU5Trj2wJ0BT5B9Nw3I= From: "slyfox at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug gcov-profile/111559] [14 regression] ICE when building Python with PGO Date: Wed, 27 Sep 2023 13:21:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: gcov-profile X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: ice-checking, ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: slyfox at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 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=3D111559 --- Comment #6 from Sergei Trofimovich --- Uninitialized value comes from `ipa_merge_profiles()` for our `rule1_same()` alias and `rule1()` functions: // in gcc/ipa-icf.cc: else if (create_alias) { alias->icf_merged =3D true; /* Remove the function's body. */ ipa_merge_profiles (original, alias); // ... If I comment out `ipa_merge_profiles (original, alias);` call to leave `original` as is then failure does not happen. Which means at least `original`'s profile is fine. Tracing through `ipa_merge_profiles()` we generate uninitialized probalility profile when divide by zero at: // in gcc/ipa-utils.cc void ipa_merge_profiles (struct cgraph_node *dst, struct cgraph_node *src, bool preserve_body) // ... /* TODO: merge also statement histograms. */ FOR_ALL_BB_FN (srcbb, srccfun) { unsigned int i; if (copy_counts) { /* snip: ireelevant */ } else { for (i =3D 0; i < EDGE_COUNT (srcbb->succs); i++) { edge srce =3D EDGE_SUCC (srcbb, i); edge dste =3D EDGE_SUCC (dstbb, i); dste->probability =3D dste->probability * dstbb->count.ipa ().probability_in (dstbb->count.ipa () + srccount.ipa ()) + srce->probability * srcbb->count.ipa ().probability_in (dstbb->count.ipa () + srccount.ipa ()); } dstbb->count =3D dstbb->count.ipa () + srccount.ipa (); } } // ... Here `dstbb->count.ipa () + srccount.ipa ()` is zero. This assert should expose it as well: --- a/gcc/ipa-utils.cc +++ b/gcc/ipa-utils.cc @@ -651,13 +651,15 @@ ipa_merge_profiles (struct cgraph_node *dst, { edge srce =3D EDGE_SUCC (srcbb, i); edge dste =3D EDGE_SUCC (dstbb, i); + + profile_count den =3D dstbb->count.ipa () + srccount.ipa = (); + gcc_assert(den.nonzero_p()); + dste->probability =3D dste->probability * dstbb->count.ipa ().probability_in - (dstbb->count.ipa () - + srccount.ipa ()) + (den) + srce->probability * srcbb->count.ipa ().probability_in - (dstbb->count.ipa () - + srccount.ipa ()); + (den); } dstbb->count =3D dstbb->count.ipa () + srccount.ipa (); } If we attach `gdb` it agrees we exercise these edges 0 times. (gdb) call dstbb->count.debug() 0 (precise) (gdb) call srccount.ipa ().debug() 0 (precise) For comparison we are trying to clobber `always` probability with `undefine= d`: (gdb) call dste->probability.debug() always What edge is that? (gdb) call debug_edge(srce) edge (bb_3, bb_4) __attribute__((noinline)) void rule1 () { int p.0_1; [count: 2]: p.0_1 =3D p; if (p.0_1 !=3D 0) goto ; [0.00%] else goto ; [100.00%] [count: 0]: edge (); [count: 2]: return; } `always` should valid for `bb_3->bb_4`. But for our data input it's `never`= .=