From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4C6813858407; Tue, 10 Jan 2023 23:36:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C6813858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673393788; bh=VqTgqx+4emZWq8KLwMAWjWYd7AUNsCw0kln0qt/GARY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GiT1YwHNFVfGanqmcrDKIfZGaOaR+RNDocZymhWlNmWMK8LFQ7fE4hgOSFm4fmp3W f/n6eOOPcXwRg57tcIq50HCs0VLbaQORC39elfDjVDhDiXnx8vs2L4qPfgeY2FP7s2 eCsJKCN5b1RmMS0VggPzQSQq4odcWUiJE4LNowQ4= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/108365] [9/10/11/12/13 Regression] Wrong code with -O0 Date: Tue, 10 Jan 2023 23:36:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org 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: 10.5 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108365 --- Comment #4 from Jakub Jelinek --- With r9-1730 or later, I think the problem is that something decides to nar= row the division from long long to int. In long long it is well defined if b is non-zero as -2147483648LL / -1LL is 2147483648LL. But when we instead narrow it to -2147483648 / -1 is UB which triggers division by zero exception. We don't seem to narrow: int foo (int x, int y) { return (long long) x / (long long) y; } so probably we do it only if the dividend is constant or something similar;= if yes, then the fix would be stop narrowing if the dividend is the minimum of= the narrower type.=