From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 767CB3858018; Tue, 11 Jan 2022 18:59:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 767CB3858018 From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99966] Bounds check not eliminated by assert Date: Tue, 11 Jan 2022 18:59:33 +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: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com 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: cc 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jan 2022 18:59:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99966 Andrew Macleod changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amacleod at redhat dot com --- Comment #2 from Andrew Macleod --- looking at VRP2: the initial assert provides: Relational : (start_4(D) < end_5(D)) Relational : (_16 > start_4(D)) Relational : (end_5(D) <=3D _16) unfortunately, the loop back edge is: i_12 =3D i_17 + 1; if (end_5(D) !=3D i_12) goto ; [89.00%] else goto ; [11.00%] so it only registers what it knows from the branch: Relational : (i_12 !=3D end_5(D)) so when it gets to the bounds check at: if (i_12 >=3D _16) goto ; [0.04%] else goto ; [99.96%] It doesn't really know the answer. If the loop branch had remained if (i_12 < end_5) instead of being changed, then we would instead get the relation: Relational : (i_12 < end_5(D)) which combined with the earlier Relational : (end_5(D) <=3D _16), should re= gister the transitive relation (i_12 < _16), and enable removal of the check. This is transformed in ivopts, which runs after vrp1. A quick check shows = at VRP1 time, the bounds are still using the < format... In fact... running with --param=3Dvrp1-mode=3Dranger registers this exact transitive relation, and produces: Relational : (i_2 < _16) Relational : (i_2 < end_5(D)) [local count: 952547451]: if (0 !=3D 0) goto ; [0.04%] else goto ; [99.96%] and eliminates the bounds check. So we can close this PR when we turn ranger on by default for VRP1.=