From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D89B7385781F; Wed, 16 Mar 2022 13:09:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D89B7385781F 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: Wed, 16 Mar 2022 13:09:41 +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: Wed, 16 Mar 2022 13:09:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104931 --- Comment #4 from Richard Biener --- (In reply to Richard Biener from comment #3) > The bug was made latent by g:51d464b608b38b9e2007948d10b1e0f1dcec142c whi= ch > ensured that >=20 > /* If the loop exits immediately, there is nothing to do. */ > tree tem =3D fold_binary (code, boolean_type_node, iv0->base, iv1->base= ); > if (tem && integer_zerop (tem)) > { > if (!every_iteration) > return false; > niter->niter =3D build_int_cst (unsigned_type_for (type), 0); > niter->max =3D 0; > return true; > } >=20 > triggered, folding (_2 + 4294967272) + 12 < _2 + 4294967272 to false. Th= at's > the following part of the revision, and it probably triggers when doing > expand_simple_operations. >=20 > diff --git a/gcc/match.pd b/gcc/match.pd > index 84c9b918041..f5dcbf32bc7 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -2143,6 +2143,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (simplify > (pointer_plus (pointer_plus:s @0 @1) @3) > (pointer_plus @0 (plus @1 @3))) > +#if GENERIC > +(simplify > + (pointer_plus (convert:s (pointer_plus:s @0 @1)) @3) > + (convert:type (pointer_plus @0 (plus @1 @3)))) > +#endif >=20=20 > /* Pattern match >=20 > It does seem to me that niter analysis relies on statically detecting > not rolling loops, at least for the cases we assume no overflow happens > and we use number_of_iterations_lt_to_ne. I can't convince myself that > only INTEGER_CST appearant negative delta are problematic for > pointer types (which we always assume to have no overflow), but that would > be the most simplistic solution here. Still "negative" delta values shou= ld > be problematic for all cases, and since we only restrict us to constant > modulo, delta can also be non-constant. I verified backporting the above fixes the issue. That's really the patch I'm most comfortable with at this point ... :/=