From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3DBA93858C74; Tue, 15 Mar 2022 10:37:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DBA93858C74 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104931] wrong-code with number_of_iterations_lt_to_ne Date: Tue, 15 Mar 2022 10:37:03 +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.2.0 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: --- 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: Tue, 15 Mar 2022 10:37:03 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104931 --- Comment #1 from Richard Biener --- I think the issue is latent on trunk. The fix should be diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index b767056aeb0..21e25cabbd2 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -1171,7 +1171,17 @@ number_of_iterations_lt_to_ne (tree type, affine_iv *iv0, affine_iv *iv1, bool exit_must_be_taken, bounds *bnds) { tree niter_type =3D TREE_TYPE (step); - tree mod =3D fold_build2 (FLOOR_MOD_EXPR, niter_type, *delta, step); + tree mod; + if (POINTER_TYPE_P (type)) + { + /* For pointers both step and delta have to be interpreted signed. = */ + mod =3D fold_build2 (FLOOR_MOD_EXPR, ssizetype, + fold_convert (ssizetype, *delta), + fold_convert (ssizetype, step)); + mod =3D fold_convert (niter_type, mod); + } + else + mod =3D fold_build2 (FLOOR_MOD_EXPR, niter_type, *delta, step); tree tmod; mpz_t mmod; tree assumption =3D boolean_true_node, bound, noloop;=