[Bug tree-optimization/104356] [12 Regression] divide by zero trap is being removed now when it should not be in some cases

ebotcazou at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Feb 3 11:14:21 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104356

--- Comment #9 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> 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)

No, the result of the operation is not dead here (modulo Volatile), so the
operation must be performed and therefore raise an exception.  To sum up,
either you optimize away the final assignment to D or you raise an exception,
i.e. D cannot contain a random value.


More information about the Gcc-bugs mailing list