From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E35B53858D37; Thu, 3 Feb 2022 11:08:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E35B53858D37 From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104356] [12 Regression] divide by zero trap is being removed now when it should not be in some cases Date: Thu, 03 Feb 2022 11:08:00 +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: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de 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: 12.0 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, 03 Feb 2022 11:08:01 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104356 --- Comment #8 from rguenther at suse dot de --- On Thu, 3 Feb 2022, ebotcazou at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104356 >=20 > Eric Botcazou changed: >=20 > What |Removed |Added > -------------------------------------------------------------------------= --- > Status|UNCONFIRMED |NEW > Ever confirmed|0 |1 > Last reconfirmed| |2022-02-03 > CC| |ebotcazou at gcc dot gnu= .org >=20 > --- Comment #7 from Eric Botcazou --- > > Hmm, but doesn't ada enable -fdelete-dead-exceptions? That is, I'm not= sure > > we make division by zero well-defined with -fnon-call-exceptions - the > > transform assumes the exception cannot happen (because undefinedness) a= nd > > removes the exceptional path. >=20 > Yes, the division by zero can be optimized away in Ada if the result of t= he > operation is not used later, so we would need to add a pragma Volatile to= the > gnat.dg/div_zero.adb testcase: >=20 > D : Integer :=3D Zero; > pragma Volatile (D); >=20 > for strict semantics, but this usually does not matter at -O0 when the re= sult > is assigned to a user variable: >=20 > D :=3D 1 / D; So for Ada it would be valid to optimize it as tem =3D D; if (tem !=3D 0) D :=3D 1 / tem; else D =3D tem; basically carrying out the division conditionally only? (I've tried hard to preserve all volatile loads / stores, if not volatile that can be elided) Does Ada define what value D obtains when D is zero or does it only allow the divison and the exceptional case to be optimized together but not separate? So optimization to tem =3D D; if (tem !=3D 0) D :=3D 1 / tem; else 1/0; and then optimizing the unused 1/0 "exceptional case" only is not allowed?=