https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104356
--- Comment #8 from rguenther at suse dot de <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=104356 > > Eric Botcazou <ebotcazou at gcc dot gnu.org> changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > Status|UNCONFIRMED |NEW > Ever confirmed|0 |1 > Last reconfirmed| |2022-02-03 > CC| |ebotcazou at gcc dot gnu.org > > --- Comment #7 from Eric Botcazou <ebotcazou at gcc dot gnu.org> --- > > 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) and > > removes the exceptional path. > > Yes, the division by zero can be optimized away in Ada if the result of the > operation is not used later, so we would need to add a pragma Volatile to the > gnat.dg/div_zero.adb testcase: > > D : Integer := Zero; > pragma Volatile (D); > > for strict semantics, but this usually does not matter at -O0 when the result > is assigned to a user variable: > > D := 1 / D; So for Ada it would be valid to optimize it as tem = D; if (tem != 0) D := 1 / tem; else D = 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 = D; if (tem != 0) D := 1 / tem; else 1/0; and then optimizing the unused 1/0 "exceptional case" only is not allowed?