From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2999D3852C45; Thu, 24 Nov 2022 10:12:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2999D3852C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669284751; bh=uQht6sZ1AP5fQ8yWK5TSwqtBJS8Uo31qIskR3eXe2Ng=; h=From:To:Subject:Date:In-Reply-To:References:From; b=q076cLp/CSREzYnbprGO9v+cwrWPMMEMPQP76jPmYB1/U9k8M3LJorQFjXPHlIRRh KqvhyqH9D9EnH7Oj6AEzUNF04ytW3Z1eiOD3872iXQx4YwTLh2D0UQ5Ln9VXM/TpkL 79hpHF89/+fFk1IfclYgtyhZwfz/RubV7AGC+Td4= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107839] spurious "may be used uninitialized" warning while all uses are under "if (c)" Date: Thu, 24 Nov 2022 10:12:30 +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: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth 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=3D107839 --- Comment #2 from Richard Biener --- We see [local count: 3508266]: if (c_4(D) !=3D 0) goto ; [33.00%] else goto ; [67.00%] [local count: 2350538]: goto ; [100.00%] [local count: 3508266]: # v_10 =3D PHI _3 =3D (unsigned int) v_10; _12 =3D _3 * 2; _1 =3D (int) _12; [local count: 354334800]: if (c_4(D) !=3D 0) goto ; [66.33%] else goto ; [33.67%] it's loop invariant motion that hoists the v + v compute out of the loop and thus outside of its controlling condition. You can see it's careful to not introduce undefined overflow that is possibly conditionally executed only but it fails to consider the case of 'v' being conditionally uninitialized. It's very difficult to do the right thing here - it might be tempting to hoist the compute as if (c) tem =3D v+v; while (1) if (c) f(tem); but apart from the technical problems in invariant motion this would cause it does introduce another variable that's only conditionally initialized and thus might be prone to false positive diagnostics. Not to mention the hoisted if (c) branch having a cost. Maybe the simplest thing would be to never hoist v + v, or only hoist it when the controlling branch is not loop invariant. The original testcase is probably more "sensible", does it still have a loop invariant controlling condition and a loop invariant computation under that control?=