From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3E0FF3858C78; Thu, 28 Mar 2024 14:05:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E0FF3858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711634758; bh=vGn1RgSXLFfRR6Uki26/FBkHisFRjS9QiV/ePf/vgIs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=utu3AxCazqZ1Q4hDRmMn18n1Q1d3+HEI/UX3FvPQXQxsP03aDdMJU4hDqA024l9ec I2ar/cDw1H9sMDmqQKFx6xb/Pit43Bgdl4kWTiOlXLTc3F/ORwino0RAX6fUxQgCHW RQPtm5YKW/sqLKEIhBrhB3yBU3tpNK8LS5AAn2A8= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/112303] [14 Regression] ICE on valid code at -O3 on x86_64-linux-gnu: verify_flow_info failed since r14-3459-g0c78240fd7d519 Date: Thu, 28 Mar 2024 14:05:53 +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: 14.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 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=3D112303 --- Comment #15 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:d5a3b4afcdf4d517334a2717dbb65ae0d2c26507 commit r14-9707-gd5a3b4afcdf4d517334a2717dbb65ae0d2c26507 Author: Jakub Jelinek Date: Thu Mar 28 15:00:44 2024 +0100 profile-count: Avoid overflows into uninitialized [PR112303] The testcase in the patch ICEs with --- gcc/tree-scalar-evolution.cc +++ gcc/tree-scalar-evolution.cc @@ -3881,7 +3881,7 @@ final_value_replacement_loop (class loop *loop) /* Propagate constants immediately, but leave an unused initialization around to avoid invalidating the SCEV cache. */ - if (CONSTANT_CLASS_P (def) && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rslt)) + if (0 && CONSTANT_CLASS_P (def) && !SSA_NAME_OCCURS_IN_ABNORMAL_= PHI (rslt)) replace_uses_by (rslt, def); /* Create the replacement statements. */ (the addition of the above made the ICE latent), because profile_count addition doesn't check for overflows and if unlucky, we can even overfl= ow into the uninitialized value. Getting really huge profile counts is very easy even when not using recursive inlining in loops, e.g. __attribute__((noipa)) void bar (void) { __builtin_exit (0); } __attribute__((noipa)) void foo (void) { for (int i =3D 0; i < 1000; ++i) for (int j =3D 0; j < 1000; ++j) for (int k =3D 0; k < 1000; ++k) for (int l =3D 0; l < 1000; ++l) for (int m =3D 0; m < 1000; ++m) for (int n =3D 0; n < 1000; ++n) for (int o =3D 0; o < 1000; ++o) for (int p =3D 0; p < 1000; ++p) for (int q =3D 0; q < 1000; ++q) for (int r =3D 0; r < 1000; ++r) for (int s =3D 0; s < 1000; ++s) for (int t =3D 0; t < 1000; ++t) for (int u =3D 0; u < 1000; ++u) for (int v =3D 0; v < 1000; ++v) for (int w =3D 0; w < 1000; ++w) for (int x =3D 0; x < 1000; ++x) for (int y =3D 0; y < 1000; ++y) for (int z =3D 0; z < 1000; ++z) for (int a =3D 0; a < 1000; ++a) for (int b =3D 0; b < 1000; ++b) bar (); } int main () { foo (); } reaches the maximum count already on the 11th loop. Some other methods of profile_count like apply_scale already do use MIN (val, max_count) before assignment to m_val, this patch just extends that to operator{+,+=3D} methods. Furthermore, one overload of apply_probability wasn't using safe_scale_64bit and so could very easily overflow as well - prob is required to be [0, 10000] and if m_val is near the max_count, it can overflow even with multiplications by 8. 2024-03-28 Jakub Jelinek PR tree-optimization/112303 * profile-count.h (profile_count::operator+): Perform addition in uint64_t variable and set m_val to MIN of that val and max_count. (profile_count::operator+=3D): Likewise. (profile_count::operator-=3D): Formatting fix. (profile_count::apply_probability): Use safe_scale_64bit even in the int overload. * gcc.c-torture/compile/pr112303.c: New test.=