From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 655B23858D28; Tue, 15 Mar 2022 13:11:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 655B23858D28 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 13:11:38 +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 13:11:38 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104931 --- Comment #2 from Richard Biener --- But maybe the code relies on a positive 'delta' - after all the same issue = must exist for integer typed IVs. Probably most interesting cases get folded ea= rly in the correct way if they do not iterate. Given niter_type is unsigned_type_for (type) the use of FLOOR_MOD_EXPR seems pointless but would be required when doing a signed floor-mod as in the fix. Note there's tree niter_type =3D TREE_TYPE (step); tree mod =3D fold_build2 (FLOOR_MOD_EXPR, niter_type, *delta, step); .. if (integer_nonzerop (mod)) mod =3D fold_build2 (MINUS_EXPR, niter_type, step, mod); .. mpz_init (mmod); wi::to_mpz (wi::to_wide (mod), mmod, UNSIGNED); mpz_neg (mmod, mmod); so there's evidence that 'mod' is assumed to be positive in the end but 'delta' can be effectively signed here. Note 'step' is the absolute value of step, it's always (made) positive. The code has been this way since Zdenek wrote it. The proposed patch has passed bootstrap & testing (but I believe it's incomplete).=