From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7D5CF3858002; Thu, 22 Jul 2021 08:07:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D5CF3858002 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/101501] [11/12 Regression] wrong code at -O3 on x86_64-linux-gnu Date: Thu, 22 Jul 2021 08:07:45 +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.1.1 X-Bugzilla-Keywords: wrong-code 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: 11.2 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 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: Thu, 22 Jul 2021 08:07:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101501 --- Comment #5 from Richard Biener --- # of iterations (a_lsm.5_10 * 52) / 52, bounded by 63 is obviously wrong with a_lsm.5_10 being a 'char', that boils down to zero iterations when computed at runtime. The loop body looks like [local count: 1073741824]: # a_3 =3D PHI d: a_6 =3D a_3 + 255; c_7 =3D a_3 * 52; if (c_7 !=3D 0) goto ; [89.00%] else goto ; [11.00%] [local count: 955630224]: goto ; [100.00%] and SCEV computes (scalar =3D c_7) (scalar_evolution =3D {a_5 * 52, +, 204}_1)) which looks correct. niter compute does static bool number_of_iterations_ne (class loop *loop, tree type, affine_iv *iv, tree final, class tree_niter_desc *niter, bool exit_must_be_taken, bounds *bnds) {=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ... /* Compute no-overflow information for the control iv. This can be proven when below two conditions are satisfied:=20 1) IV evaluates toward FINAL at beginning, i.e: base <=3D FINAL ; step > 0 base >=3D FINAL ; step < 0 2) |FINAL - base| is an exact multiple of step. ... if (!niter->control.no_overflow && (integer_onep (s) || multiple_of_p (type, c, s))) { and there we have the issue of multiple_of_p not handling overflow (there's a duplicate bug, PR100499 about this issue). The 1) condition ends up as unsigned-val >=3D 0 which is trivially true.=